Example:
print max(chain_length(i) for i in xrange(1,10001))
This returns the maximum/biggest "chain_length" (an arbitrary function), but what I want is the i
value for input that produces the biggest value.
Is there a convenient way to do that?
The max() method returns the largest value from the specified iterable or multiple arguments.
The Python max() function returns the largest value in an iterable, such as a list. If a list contains strings, the last item alphabetically is returned by max().
Python – max() function. Python max() function returns the largest item in an iterable or the largest of two or more arguments. It has two forms.
max(xrange(1, 10001), key=chain_length)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With