Reputation: 33213
I have a list of string like:
s = [("abc","bcd","cde"),("123","3r4","32f")]
Now I want to convert this to the following:
output = ["abcbcdcde","1233r432f"]
What is the pythonic way to do this? THanks
Upvotes: 2
Views: 10965
Reputation: 133504
>>> map(''.join, s)
['abcbcdcde', '1233r432f']
That should do it
Upvotes: 7
Reputation: 29093
Not a real answer, just want to check, what about reduce and operator.add, i read that in such a way both of them would perform quite fast and effective, or i am wrong?
s = [("abc","bcd","cde"),("123","3r4","32f")]
from operator import add
[reduce(add, x) for x in s]
Upvotes: 0
Reputation: 940
How about this:
>>> map(lambda x: ''.join(x), s)
['abcbcdcde', '1233r432f']
Upvotes: 0
Reputation: 798456
>>> [''.join(x) for x in s]
['abcbcdcde', '1233r432f']
Upvotes: 18