Find n largest / n smallest numbers in a list
import heapq grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] print(heapq.nlargest(3, grades)) # 110, 90, 87 print(heapq.nsmallest(4, grades)) # 25, 20, 33, 38