On Wed, Mar 02, 2022 at 02:28:33AM +0100, Svein Seldal wrote:
for x in y if x in c: some_op(x)
What does this new syntax give us that we don't already have with this? for x in y if x in c: some_op(x) or the other multiple ways of writing the equivalent code? I see no new functionality here. Is the only advantage that you save one line and one indent level? Both are cheap. To be precise, one extra line in something which is already a multiline statement is essentially insignificant, and while an extra indent level *can* be important, if you have already used so many indents that it becomes important, you probably should be refactoring your code. All I see here is adding to the complexity of the parser and the language for no meaningful benefit. Its not even easier to read, it crams more on one line which in real code with meaningful variable names and a meanigful condition starts to get a bit long: # this line desperately needs to be split over two lines for student in students if mean(student.grade(subject) for subject in student.get_subjects()) > 0.8): ... When I write list comprehensions with an if condition, probably 90% of the time I end up moving the if condition to a second or even third line of the comprehension. I expect the same will apply here. To save one line for maybe 10% of my for...if constructs, I don't think it is worth the bother of adding yet another way to do it. -- Steve