extended list comprehensions
Raymond Hettinger
python at rcn.com
Tue May 28 09:50:33 EDT 2002
"F. Jamitzky" <fxj at hotmail.com> wrote in message
news:f32195af.0205261316.2482d4ac at posting.google.com...
> It would be great to have something like a list comprehension for the
> reduce function. It would work in the same way as the comprehension
> for the map function, which is:
>
> [foo(x) for x in xs] <-is the same as-> map(foo,xs)
>
> and maybe it could be written as:
>
> {y=y+x for x in xs} <-would be-> reduce(operator.add,xs)
Perhaps this syntax would be cleaner:
for x in xs: y=y+x
Raymond Hettinger
More information about the Python-list
mailing list