←back to thread

317 points est | 1 comments | | HN request time: 0.205s | source
Show context
BerislavLopac ◴[] No.17448998[source]
I would like to see adding a comprehension-like filtering clause to for-statements:

    for n in range(100) if n%2:
        print(f'{n} is odd number')
Does anyone know if there is a PEP covering that?
replies(5): >>17449022 #>>17449029 #>>17449035 #>>17449036 #>>17452328 #
1. UncleEntity ◴[] No.17452328[source]
I write that all the time and when python complains I usually rewrite it to something like:

for odd_numbers in [n for n in range(100) if n%2]:

after a quick "stupid python" comment.