max(), sum(), next()

Odalrick odalrick at hotmail.com
Sun Sep 7 12:12:53 EDT 2008


bearophileHUGS at lycos.com wrote in news:240454f2-14ee-496a-9078-1abbf80a4e64
@m45g2000hsb.googlegroups.com:

> 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