Convenient filtering in for cycles
Stefano Maggiolo
s.maggiolo at gmail.com
Wed Oct 5 14:05:00 EDT 2011
Dear Ian,
thank you for you kind response. I was pretty confident the issue had
already been discussed, but I was unable to look it up.
I suppose your "filter" syntax is the best given the options (I always
forget about map and filter...) and definitely I see that the work
needed to add such a feature is hardly worth the convenience.
Still, I think it is sad that generators/list comprehensions and for
cycles do not share the same syntax. Unfortunately, this example from
one of your links convinces that anyway it is too late:
(x for x in (l1 if c else l2)) # valid
(x for x in l1 if c else l2) # SyntaxError
for x in l1 if c else l2 # valid
Cheers,
Stefano
More information about the Python-list
mailing list