2 ms·
The min() function doesn't know the type. The minimum possible value for a list of strings is "", for example. To get what you want, use min(lst, default=-math
by eesmith 7y ago
The min() function doesn't know the type. The minimum possible value for a list of strings is "", for example.
To get what you want, use min(lst, default=-math.inf) .
- eru 7y agoAgreed. In Python 2, you had float('-inf') < "" So you could sort of get away with that. But that positive infinity wasn't bigger than any string. And in Python 3 comparing strings and numbers just results in an error.
- billpg 7y agoMax returns a string with an infinite number of U+1FFFFs for an empty collection. True story.