If I had two lists like these
["John", "Jim", "Jimmy"]
["100", "200", "300"]
How would I be able to merge the lists so that the first item in each list matches up with the other first item and so on like this
["John100", "Jim200", "Jimmy300"]
If I had two lists like these
["John", "Jim", "Jimmy"]
["100", "200", "300"]
How would I be able to merge the lists so that the first item in each list matches up with the other first item and so on like this
["John100", "Jim200", "Jimmy300"]
Use zip()
for this:
list1 = ["John", "Jim", "Jimmy"]
list2 = ["100", "200", "300"]
merged = [l1 + l2 for l1, l2 in zip(list1, list2)]
print(merged)
Output:
['John100', 'Jim200', 'Jimmy300']