programming-examples/python/List/Python program to find the second smallest number in a list.py

9 lines
259 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
def second_smallest(numbers):
a1, a2 = float('inf'), float('inf')
for x in numbers:
if x <= a1:
a1, a2 = x, a1
elif x < a2:
a2 = x
return a2
print(second_smallest([1, 2, -8, -2, 0]))