r/pythonhelp • u/pacukluka • Dec 14 '17
Merging 2 lists of same length
list1 = ["a","b"] list2 = ["c","d"]
<some magic here>
out:
["ac","bd"]
3
Upvotes
r/pythonhelp • u/pacukluka • Dec 14 '17
list1 = ["a","b"] list2 = ["c","d"]
<some magic here>
out:
["ac","bd"]
1
u/ojiisan Jan 17 '18 edited Jan 17 '18
The zip function takes the two lists and creates a new list of 2-tuples that contain pairs of elements (in order) from the original lists:
which isn't quite what you want. So the map function then takes the output from zip and applies the join function (with an empty string as the joining item) to each of the tuples, resulting in the merged list you were looking for.