如何互相添加列表的元素(StringType)

时间:2019-01-23 03:25:05

标签: python python-3.x

我有一个这样的列表:

list1 = [["A","B","C"],["a","b","c"],["1","2","3"]]

如何将其转换为:

["Aa1","Bb2","Cc3"]

2 个答案:

答案 0 :(得分:3)

您可以使用zipjoin

list1 = [["A","B","C"],["a","b","c"],["1","2","3"]]

result = [''.join(s) for s in zip(*list1)]
print(result)

输出:

['Aa1', 'Bb2', 'Cc3']

答案 1 :(得分:0)

listmap一起使用,此处的密钥为Transpose list of lists

list(map(''.join,zip(*list1)))
['Aa1', 'Bb2', 'Cc3']