Created
October 21, 2022 15:21
-
-
Save mh0w/4cd0d5820b03db5a506e844c3d20ce6a to your computer and use it in GitHub Desktop.
get N largest values from a list
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
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