Skip to content

Instantly share code, notes, and snippets.

@mh0w
Created October 21, 2022 15:21
Show Gist options
  • Save mh0w/4cd0d5820b03db5a506e844c3d20ce6a to your computer and use it in GitHub Desktop.
Save mh0w/4cd0d5820b03db5a506e844c3d20ce6a to your computer and use it in GitHub Desktop.
get N largest values from a list
import heapq
print(heapq.nlargest(3, [10, 5, 3, 8, 4, 2])) # [10, 8, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment