I'm trying to use map
in Python3. Here's some code I'm using:
import csv
data = [
[1],
[2],
[3]
]
with open("output.csv", "w") as f:
writer = csv.writer(f)
map(writer.writerow, data)
However, since map
in Python3 returns an iterator, this code doesn't work in Python3 (but works fine in Python2 since that version of map
always return a list
)
My current solution is to add a list
function call over the iterator to force the evaluation. But it seems odd (I don't care about the return value, why should I convert the iterator into a list?)
Any better solutions?