List minimum in Python with None?
None
is being returned
>>> print min([None, 1,2])
None
>>> None < 1
True
If you want to return 1
you have to filter the None
away:
>>> L = [None, 1, 2]
>>> min(x for x in L if x is not None)
1
using a generator expression:
>>> min(value for value in [None,1,2] if value is not None)
1
eventually, you may use filter:
>>> min(filter(lambda x: x is not None, [None,1,2]))
1