On 8/30/2013 8:09 PM, Steven D'Aprano wrote:

We really are spoiled for choice here. We can write any of these:

# Option 1
for spam in sequence:
     if predicate(spam):
         process(spam)

# Option 2
for spam in filter(predicate, sequence):
     process(spam)

# Option 3
for spam in (spam for spam in sequence if predicate(spam)):
     process(spam)


Adding a fourth option:

for spam in sequence if predicate(spam):
     process(spam)

saves absolutely nothing except a line and an indent level, neither of
which are in short supply, and gains nothing in readability over Option 1.

Which is why it has been rejected.

But of all the options shown, including the hypothetical for...if, I
still prefer Option 1, or Option 2 as my second option.

Ditto.

I think people would be better off spending more time learning more about how to use this incredibly powerful tool we have and less arguing for rejected redundant alternatives to what we do have. Just a few days ago, after 16 years of Python, I learned something really neat about function attributes of instances that made a certain testing problem disappear.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to