Last active
November 12, 2017 19:50
-
-
Save DGrady/7dc82dbd0a81ee743a65f05761d7d5f2 to your computer and use it in GitHub Desktop.
Return the minimum and maximum values from an iterable in one pass
This file contains hidden or 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
def extent(collection): | |
""" | |
Return the minimum and maximum values from an iterable in one pass | |
""" | |
itr = iter(collection) | |
first_value = next(itr) | |
minimum = first_value | |
maximum = first_value | |
for v in itr: | |
minimum = min(v, minimum) | |
maximum = max(v, maximum) | |
return (minimum, maximum) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment