For SchroedingersLion sake I add one additional tidbit to consider when comparing those two solutions:
zip() produces iterator and you can consume it only once. Depending on your needs and in order to avoid nasty surprises you should be aware of following (expected) behaviour:
(Dec-19-2018, 12:58 PM)buran Wrote: Actually option2 can be simplified even further
data = zip(x2, y2) result_writer.writerows(data)or even as one-liner
result_writer.writerows(zip(x2, y2))
zip() produces iterator and you can consume it only once. Depending on your needs and in order to avoid nasty surprises you should be aware of following (expected) behaviour:
>>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zip(x, y) # iterator created >>> list(zipped) # iterator consumed [(1, 4), (2, 5), (3, 6)] >>> list(zipped) # exhausted iterator [] >>> list(zip(x, y)) # iterator created and consumed [(1, 4), (2, 5), (3, 6)] >>> list(zip(x, y)) # iterator created again and consumed [(1, 4), (2, 5), (3, 6)]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.