user2240542
user2240542

Reputation: 79

is there a way to join list of strings in sublist

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']]

Upvotes: 2

Views: 794

Answers (2)

pondohva
pondohva

Reputation: 113

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']]

Upvotes: -1

jamylak
jamylak

Reputation: 133514

>>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
>>> [[''.join(x)] for x in L]
[['ab'], ['cd'], ['ef'], ['g']]

Upvotes: 6

Related Questions