Sep-24-2018, 07:12 AM
But that is what's happening. It's exactly the same as map/filter, if you consume all of the input at once:
>>> def do_something_with(x): ... print(x**2) ... >>> def is_valid(x): ... return x % 2 == 0 ... >>> things = range(10) >>> [do_something_with(x) for x in things if is_valid(x)] 0 4 16 36 64 [None, None, None, None, None] >>> list(map(do_something_with, filter(is_valid, things))) 0 4 16 36 64 [None, None, None, None, None]