Chris Angelico writes:
> What Python needs is not a way to cram more onto one line. What Python
> needs is a way to express an abstract concept: "iterate over the
> interesting parts of this collection".
Python has one, and you've already mentioned it:
for thing in (x for x in this_collection if is_interesting(x)):
It's noticably verbose, but it's an exact translation of your
statement of the abstract concept above. It has all the benefits of
the proposed syntax except compactness[1].
I'd have to see a fair number of examples to decide whether I think
saving len(" (x for x in)") == 13 characters allows enough additional
filtered iterations to be comfortably expressed on one line to be
worth new syntax. I suspect that the redundancy and grouping
parenthesis aspects won't make much difference for anything more
complicated than the above, but they might.
Steve
Footnotes:
[1] By "compactness" I mean all of brevity, DRY, and absence of
grouping parentheses. I don't know if that's a useful term to
summarize all of those, but let me throw it out there.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/M43LTMQWBN252IRVGVQJNXNJPWPY3542/
Code of Conduct: http://python.org/psf/codeofconduct/