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
  • 272
  • 1
  • 3
  • 15
thecheech
  • 1,811
  • 2
  • 16
  • 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
  • 232,417
  • 55
  • 437
  • 487
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
  • 29,826
  • 8
  • 62
  • 75
2

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

print [m + n for m, n in zip(listone, listtwo)]
gravetii
  • 8,485
  • 8
  • 49
  • 69
0

you can also use join instead of +

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