>>> def secondsmallest(L):
... a, b = None, None
... for item in L:
... if a is None or item <= b:
... a, b = item, a
... elif b is None or item <= a:
... b = item
... return b
>>> secondsmallest([4, 5, 1, 2, 3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in secondsmallest
TypeError: '<=' not supported between instances of 'int' and 'NoneType'
For example:
secondsmallest()does not account for when the second element inLis larger than the first element.