Open this example in the interactive library
Source code
import heapq
print(heapq.nlargest(3, [4, 9, 2, 7, 5]))Sample output
[9, 7, 5]

Find the three largest values. A self-contained example using the Python standard library.
Open this example in the interactive library
import heapq
print(heapq.nlargest(3, [4, 9, 2, 7, 5]))[9, 7, 5]