import heapq numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] smallest_three = heapq.nsmallest(3, numbers) print(smallest_three) largest_three = heapq.nlargest(3, numbers) print(largest_three)