Skip to content

Instantly share code, notes, and snippets.

@DGrady
Last active November 12, 2017 19:50
Show Gist options
  • Save DGrady/7dc82dbd0a81ee743a65f05761d7d5f2 to your computer and use it in GitHub Desktop.
Save DGrady/7dc82dbd0a81ee743a65f05761d7d5f2 to your computer and use it in GitHub Desktop.
Return the minimum and maximum values from an iterable in one pass
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