Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge all the elements in a list python

Tags:

python

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

like image 638
frazman Avatar asked Mar 18 '26 14:03

frazman


2 Answers

>>> [''.join(x) for x in s]
['abcbcdcde', '1233r432f']
like image 69
Ignacio Vazquez-Abrams Avatar answered Mar 22 '26 10:03

Ignacio Vazquez-Abrams


>>> map(''.join, s)
['abcbcdcde', '1233r432f']

That should do it

like image 29
jamylak Avatar answered Mar 22 '26 11:03

jamylak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!