Reputation: 2211
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"]
Upvotes: 0
Views: 275
Reputation: 596
you can also use join
instead of +
print [''.join(x) for x in zip(listone, listtwo)]
Upvotes: 1
Reputation: 9624
You can use list comprehension and the zip()
method-
print [m + n for m, n in zip(listone, listtwo)]
Upvotes: 2
Reputation: 250881
Use map
:
>>> from operator import add
>>> one = ["a", "b", "c"]
>>> two = ["d", "e", "f"]
>>> map(add, one, two)
['ad', 'be', 'cf']
Upvotes: 4
Reputation: 32189
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']
Upvotes: 3