I have the following sublist:
[['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
But is it possible to join the list in the sublist?
[['ab'], ['cd'], ['ef'], ['g']]
>>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
>>> [[''.join(x)] for x in L]
[['ab'], ['cd'], ['ef'], ['g']]
Also, you can use map for it
>>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
>>> map(lambda x: [''.join(x)], L)
[['ab'], ['cd'], ['ef'], ['g']]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.