[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:
Joshua Landau
joshua.landau.ws at gmail.com
Wed Jul 3 05:05:27 CEST 2013
On 1 July 2013 16:21, Shane Green <shane at umbrellacode.com> wrote:
>
> Having a bit of a hard time following the status of this as I dropped out
for a while, but I’m not really for the semi-colon separator approach. Of
all the options already available in list comprehensions, this one actually
seems to be one of the most easily because it starts with a keyword and
ends at the end. Not that syntax highlighting should be taken into account
in general, it’s worth noting the syntax highlighted version really makes
this distinction quite clear:
<IMG>
That's somewhat convincing. I'm still not convinced we need new syntax
though. \
> One thing I could see doing would be to allow semi-colons anywhere in a
list comprehension that’s a boundary between statements of the expanded
form.
>
> Then they behave just like the optional semi-colons you could put at the
end of a line.
>
> Sorry if that’s precisely what’s been promoted. .
So (I'm just adding examples to your idea):
[item for sublist in data for item in sublist; if item]
can become
[item; for sublist in data; for item in sublist; if item]
In a pathological case this is a transform from:
[item for sublist in data if sublist for item in sublist if item%3 if
item-1]
to
[item for sublist in data; if sublist; for item in sublist; if item%3;
if item-1]
But you can always do:
[item
for sublist in data if sublist
for item in sublist if item%3
if item-1]
That said, it's not like people *do* those sorts of pathological
expressions, is it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130703/e97c95ab/attachment-0001.html>
More information about the Python-ideas
mailing list