max(), sum(), next()

David C. Ullrich dullrich at sprynet.com
Fri Sep 5 11:22:22 EDT 2008


In article 
<18c765e0-1dcb-4e40-93a9-32bb9d129b7e at n38g2000prl.googlegroups.com>,
 bearophileHUGS at lycos.com wrote:

> David C. Ullrich:
> > At least in mathematics, the sum of the elements of
> > the empty set _is_ 0, while the maximum element of the
> > empty set is undefined.
> 
> What do you think about my idea of adding that 'default' argument to
> the max()/min() functions?

How the Python max and min functions should work has to
do with how people want them to work and how people expect
them to work. I wouldn't know about most people, but I
would have been surprised if min([]) was not an error,
and I would have been disappointed if sum([]) was not 0.

>From a mathematical point of view, not that that's directly
relevant, it doesn't make much sense to me to add that default
argument. The max of a set is supposed to be the largest
element of that set. If the set is empty there's no such
thing.

In Python you'd better make sure that S is nonempty before
asking for max(S). That's not just Python - in math you need
to make certain that S is nonempty and also other conditions
before you're allowed to talk about max(S). That's just the
way it is.

Think about all the previously elected female or black
presidents of the US. Which one was the tallest?

> Bye,
> bearophile

-- 
David C. Ullrich



More information about the Python-list mailing list