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
list(map(lambda x: do(x),y))
will trigger an evaluation and stay in the nice, readable semantics that improve human runtime efficiency beyond the "for-loop (which is a map itself) plus new paragraph scope transition" semantics. ¯\(ツ)/¯
Note that there is no reason not to call it semantic sugar during an initial draft (in fact, for loops are usually easier since they are more modular: you may not know what your code needs to do during your first try at a problem), but when you are productionalizing or reverse engineering code that is in a working state, increasing semantic efficiency (or even merely rewriting in equivalently nice code) is a strong factor of success.
Anyhow, if you want to flush the map
stack, trigger it with a list
type conversion.
So:
import csv
data = [
[1],
[2],
[3]
]
with open("output.csv", "w") as f:
writer = csv.writer(f)
list(map(writer.writerow, data))