max(), sum(), next()

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Sep 4 22:43:43 CEST 2008


castironpi:
> For max and min, why can't you just add your argument to the set
> itself?

Sometimes that can be done, but in many other situations it's less
easy, like in the example I have shown in my first post:

max((fun(x) for x in iterable if predicate(x)))

There are some ways to add the max there, for example using an
itertools.chain to chan the default value to the end of the iterable,
but most of the time I just write a for loop.

Bye,
bearophile



More information about the Python-list mailing list