←back to thread

317 points est | 1 comments | | HN request time: 0.384s | 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. netheril96 ◴[] No.17449022[source]
Does this save anything? The canonical way to do this is

    for n in range(100):
        if n%2:
            print(f'{n} is odd number')
Only two more indents. What is the point of your proposed syntax?