In [1]:
import heapq
In [2]:
l = [3, 6, 7, -1, 23, -10, 18]
In [3]:
print(heapq.nlargest(3, l))
In [4]:
print(heapq.nsmallest(3, l))
In [5]:
print(l)