-1

I have two lists

   list1 = ['1','2','3']

   list2 = ['4','5','6']

desire list3 to be ['14','25','36']

Is there a python built in function that can do this?

I have searched for a method to do this but have not found anything. Everything all the functions simply append one list to the other. Not what I want to do

Dean-O
  • 1,143
  • 4
  • 18
  • 35

3 Answers3

2

We can do it using map:

list1 = ['1', '2', '3']
list2 = ['4', '5', '6']

list3 = list(map(''.join, zip(list1, list2)))
print(list3)

#['14', '25', '36']
AziMez
  • 2,014
  • 1
  • 6
  • 16
1

Try this:

list3 = [x+y for x, y in zip(list1, list2)]
Tom Karzes
  • 22,815
  • 2
  • 22
  • 41
1

To iterate through several lists at a time, you can use the zip() function. Something like this would work:

list1 = ['1','2','3']
list2 = ['4','5','6']
list3 = [a + b for a, b in zip(list1, list2)]

The zip function will iterate through both lists, concatenate each element, and put the result into list3.

Ben Felson
  • 21
  • 4