import heapq def second_smallest(numbers): return heapq.nsmallest(2, numbers)[-1] second_smallest([1, 2, 3, 4]) # Output: 2