18

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?

1 Answer 1

30
max(xrange(1, 10001), key=chain_length)
Sign up to request clarification or add additional context in comments.

1 Comment

Didn't know about the key parameter. That's awesome! Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.