0

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"]
Mitchell
  • 27
  • 4

1 Answers1

1

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']
bherbruck
  • 2,167
  • 1
  • 6
  • 17