Question about list comprehension/standard "for" disparities

Nathan Rice nathan.alexander.rice at gmail.com
Wed Mar 31 13:58:58 EDT 2010


I was just wondering, why the list/generator and standard "for" have
disparities?

It would be really nice to be able to do:

for x in y if foo:
    ...

rather than:

for x in (x for x in y if foo):
    ...

Also, from a style standpoint, I prefer to extract the loop logic into a
function if it's more than a few lines long.  As a result, most of my loops
are of the form:

for x in y:
    bar(x)

So I frequently end up using map.  As I understand it, there is some
discussion of removing map() in favor of comprehensions.  Is there any
reason why the for syntax could not be expanded to accommodate statements of
the form:

bar(x) for x in y

?

This inconsistency really bothered me when I started playing with python,
and it seems kind of at-odds with the "one right way to do things"
mentality.

-Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100331/6a243510/attachment.html>


More information about the Python-list mailing list