[Python-ideas] 'where' statement in Python?

Bruce Leban bruce at leapyear.org
Tue Jul 20 21:42:15 CEST 2010


List comprehensions are the one place where I might find this useful. I can
do this with map though:

[y for x in another_list if y < 5 where y = f(x)]
[y for x in map(f, another_list) if x < 5]

[x for x in another_list if y < 5 where y = f(x)]
[x for (x,y) in map(lambda x: (x,f(x)), another_list) if y < 5]


I think the variant with 'where' or 'with' would be a bit more readable but
is it valuable enough?

--- Bruce
http://www.vroospeak.com
http://google-gruyere.appspot.com



On Tue, Jul 20, 2010 at 7:57 AM, Andrey Popp <8mayday at gmail.com> wrote:

>
>
>    mylist = [y for y in another_list if y < 5 where y = f(x)]
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100720/bb54dda6/attachment.html>


More information about the Python-ideas mailing list