I’m sure that this is pretty easy to do but I’m not sure how to do it.
I have three lists: list1=[a1, a2, a3...], list2=[b1, b2, b3...], and list3=[c1, c2, c3...]
I want to pass a list that is a by-item merger of these three:
finalList = [[a1, b1, c1,], [a2, b2, c2], [a3, b3, c3]...]
How do I do this?
That’s what the built-in
zip()is for:Note that
final_listwill actually be a list of tuples, and its length will be the length of the shortest input list.The functions
itertools.izip()anditertools.izip_longest()are also noteworthy.