
Comprehending Python's (List|Dict|Set) Comprehensions - dbader
https://dbader.org/blog/list-dict-set-comprehensions-in-python#hn
======
ericfrederich
... don't forget generator comprehension

    
    
        l = [x**2 for x in range(20) if x**2 % 2 == 0]
        s = {x**2 for x in range(20) if x**2 % 2 == 0}
        d = {x: x**2 for x in range(20) if x**2 % 2 == 0}
        g = (x**2 for x in range(20) if x**2 % 2 == 0)
    

you can use that to create an infinite generator

    
    
        g = (x**2 for x in itertools.count() if x **2 % 2 == 0)
        for thing in g:
          print(thing)

