import heapq
with open('nums.txt') as f:
    numbers = map(int, f.readlines())
print(heapq.nlargest(10, numbers))
print(heapq.nsmallest(10, numbers))
How can I sort 1 million numbers, and only print the top 10 in Python?