Non-lazy evaluation version of map in Python3?

Using map for its side-effects (eg function call) when you’re not interested in returned values is undesirable even in Python2.x. If the function returns None, but repeats a million times – you’d be building a list of a million Nones just to discard it. The correct way is to either use a for-loop and call:

for row in data:
    writer.writerow(row)

or as the csv module allows, use:

writer.writerows(data)

If for some reason you really, really wanted to use map, then you can use the consume recipe from itertools and generate a zero length deque, eg:

from collections import deque
deque(map(writer.writerow, data), maxlen=0)

Leave a Comment