functional programming with map()

Paul Rubin phr-n2002a at nightsong.com
Mon Feb 25 00:59:51 EST 2002


bokr at oz.net (Bengt Richter) writes:
> but I didn't get an extra call trying your version:
> 
>  >>> reduce(lambda x,y:(y.f(),0)[1], items, 0)
>  this is a
>  this is b
>  this is c
>  0

Didn't you?  'items' had three elements, but four values got printed.

> you can use the 'and 0' ploy to get a zero length
> list comprehension also:
> 
>  >>> [ 0 for x in items if x.f() and 0]
>  this is a
>  this is b
>  this is c
>  []

Nice!  That's the best solutions so far.



More information about the Python-list mailing list