max(), sum(), next()

Odalrick odalrick at
Sun Sep 7 18:12:53 CEST 2008

bearophileHUGS at wrote in news:240454f2-14ee-496a-9078-1abbf80a4e64

> 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.

Is there any problem with:
max(initial_value, *(fun(x) for x in iterable if predicate(x) ) )


More information about the Python-list mailing list