
On Sun, 6 Mar 2022 at 21:41, Christopher Barker <pythonchb@gmail.com> wrote:
Personally, I'm certainly not ignoring comprehensions. "for thing in (x for x in collection if is_interesting(x))" uses comprehensions just fine, if you don't like the verbosity of "x for x in", then that's an issue with comprehensions, not a reason why comprehensions don't address this issue, surely? (Personally, I find the repetitiveness of "x for x in" mildly annoying, but not enough to put me off comprehensions[1]).
Earlier on the thread, I made a similar point that it would be nice to have a way to filter without the redundant for x in x. Though I can’t think of a really good way to express it. But as for filtered for loops:
"for thing in (x for x in collection if is_interesting(x))"
It not so much the extraneous “x for x” as the duplicated “for thing in” that bugs me.
I’m curious— to the skeptics: do you think that The above (or a later if block) is just as good or better than
for thing in collection if isinteresting(thing):
Or just that it’s not worth it to make a change.
I think that for thing in collection: if not isinteresting(thing): break ... is at least as good as for thing in collection if isinteresting(thing): ... and better in many ways (most importantly for me, it works in older versions of Python, which is important for libraries that support multiple versions). I think that for thing in (x for x in collection if isinteresting(x)): ... is only marginally worse, and not sufficiently worse to justify new syntax.
But the other part of why I think comprehensions are relevant is that introducing anf if to the for statement is not brand new syntax - it would be allowing existing syntax in a new context that is highly related.
Agreed, this makes the impact of new syntax smaller. But I'm not really worried about that. It's not that it's a big change, just that it *is* a change, and there's a minimal cost for *any* change to the language definition. So someone has to care enough to pay that cost (in terms of writing a PEP, an implementation, and documentation, and in terms of going through the process of getting the change accepted).
And as for documentation and all that, it’s hard to imagine very many people not understanding what it means.
Do I care enough to write a PEP? No. So this, like many other small ideas, will probably die on the vine.
Yes, this is the real problem. It's simply not compelling enough, even for supporters of the idea, for them to do the necessary work to make it happen.
Oh well.
Indeed. Paul