如何在Python中加入兩個字符列表?在Python中加入兩個字符列表
例子:
listone = [a,b,c]
listtwo = [d,e,f]
輸出:
Joinedlist == [ad, be, cf]
如何在Python中加入兩個字符列表?在Python中加入兩個字符列表
例子:
listone = [a,b,c]
listtwo = [d,e,f]
輸出:
Joinedlist == [ad, be, cf]
首先,您的字符應該是單/雙引號:
listone = ['a', 'b', 'c']
listtwo = ['d', 'e', 'f']
然後,你可以這樣做:
listthree = [i+j for i,j in zip(listone,listtwo)]
>>> print listthree
['ad', 'be', 'cf']
您可以使用列表中理解和zip()
方法 -
print [m + n for m, n in zip(listone, listtwo)]
你也可以使用join
代替+
print [''.join(x) for x in zip(listone, listtwo)]
你得到一些質量答案對於你的問題,但爲了將來的參考,請記住包括一些信息關於你*已經試圖解決你的問題中的某個問題。相關/接壤重複:[在python中加入兩個列表到元組中](http://stackoverflow.com/q/21196165/1199226) – itsjeyd