I\'ve written a for-loop using map, with a function that has a side-effect. Here\'s a minimal working example of what I mean:
def someFunc(t):
n, d = t
d
You don't want to do this (run a map()
just for the side effects), but there is a itertools consume recipe that applies here:
from collections import deque
deque(map(somefunc, ((i,d) for i in range(10**3))), maxlen=0)
The collections.deque() object, configured to a maximum size of 0, consumes the map()
iterable with no additional memory use. The deque
object is specifically optimized for this use-case.