[Python-ideas] Break the dominance of boolean values in boolean context
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Sep 15 00:45:23 CEST 2011
Terry Reedy wrote:
> You should turn the question around, any([]) returns the identity
> element for any(), so why does't max([])? Because Python does not have
> an artificial universal minimum object.
Even if it did, it wouldn't necessarily make sense for max() to
return it. max(s) means "the largest member of set s", and for it
to return something that wasn't a member of s would be perverse.
In every case I've encountered where there's a possibility of
min() or max() being applied to an empty collection, the empty
state had to be treated as a special case anyway. So it's just
as easy to test for the empty case before calling min() or max().
--
Greg
More information about the Python-ideas
mailing list