0

I want to make a new list concatenating the corresponding elements of lists of equal-sized strings. For instance, for

list1 = ["a","b","c"]
list2 = ["d","e","f"]

, the output should be

["ad", "be", "cf"]
niamulbengali
  • 292
  • 1
  • 3
  • 16
thecheech
  • 2,041
  • 3
  • 18
  • 25
  • 1
    You are getting some quality answers for your question, but for future reference, do remember to include some information about what *you* already tried to solve a given problem in your questions. Related/bordering on duplicate: [Joining two lists into tuples in python](http://stackoverflow.com/q/21196165/1199226) – itsjeyd Apr 23 '14 at 08:04

4 Answers4

4

Use map:

>>> from operator import add
>>> one = ["a", "b", "c"]
>>> two = ["d", "e", "f"]
>>> map(add, one, two)
['ad', 'be', 'cf']
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
3

Firstly, your chars should be in single/double quotes:

listone = ['a', 'b', 'c']
listtwo = ['d', 'e', 'f']

Then you can do:

listthree = [i+j for i,j in zip(listone,listtwo)]

>>> print listthree
['ad', 'be', 'cf']
sshashank124
  • 31,495
  • 9
  • 67
  • 76
2

You can use list comprehension and the zip() method-

print [m + n for m, n in zip(listone, listtwo)]
gravetii
  • 9,273
  • 9
  • 56
  • 75
1

you can also use join instead of +

print [''.join(x) for x in zip(listone, listtwo)]
yejinxin
  • 586
  • 1
  • 3
  • 13