Created
July 5, 2019 19:30
-
-
Save eyaltrabelsi/a417d85d039e1df86715bef3ff808821 to your computer and use it in GitHub Desktop.
Python trick for getting max/min values from iterables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Getting maximum from iterable | |
>>> a = [1, 2, -3] | |
>>> max(a) | |
2 | |
# Getting maximum from iterable | |
>>> min(a) | |
1 | |
# Bot min/max has key value to allow to get maximum by appliing function | |
>>> max(a,key=abs) | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't getting minimum of a
min(a) output -3
while min(a, key=abs) will output 1