我有一个字符串列表,如:
s = [("abc","bcd","cde"),("123","3r4","32f")]
现在我想将其转换为以下内容:
output = ["abcbcdcde","1233r432f"]
这样做的pythonic方法是什么? 感谢
答案 0 :(得分:15)
>>> [''.join(x) for x in s]
['abcbcdcde', '1233r432f']
答案 1 :(得分:7)
>>> map(''.join, s)
['abcbcdcde', '1233r432f']
应该这样做
答案 2 :(得分:1)
output = []
for grp in s:
output.append(''.join(grp))
答案 3 :(得分:0)
这个怎么样:
>>> map(lambda x: ''.join(x), s)
['abcbcdcde', '1233r432f']
答案 4 :(得分:0)
不是一个真正的答案,只是想检查一下,还有什么关于reduce和operator.add,我读到它们会以这样的方式表现得非常快速有效,或者我错了吗?
s = [("abc","bcd","cde"),("123","3r4","32f")]
from operator import add
[reduce(add, x) for x in s]