如何在Python中加入两个字符列表?
示例:
listone = [a,b,c]
listtwo = [d,e,f]
输出:
Joinedlist == [ad, be, cf]
答案 0 :(得分:4)
使用map
:
>>> from operator import add
>>> one = ["a", "b", "c"]
>>> two = ["d", "e", "f"]
>>> map(add, one, two)
['ad', 'be', 'cf']
答案 1 :(得分:3)
首先,你的字符应该是单/双引号:
listone = ['a', 'b', 'c']
listtwo = ['d', 'e', 'f']
然后你可以这样做:
listthree = [i+j for i,j in zip(listone,listtwo)]
>>> print listthree
['ad', 'be', 'cf']
答案 2 :(得分:2)
您可以使用列表推导和zip()
方法 -
print [m + n for m, n in zip(listone, listtwo)]
答案 3 :(得分:0)
您也可以使用join
代替+
print [''.join(x) for x in zip(listone, listtwo)]