Reputation: 524
I have a list like this:
lst = [['one two', 'three'], ['four five', 'six']]
I need to make:
lst = [['one', 'two', 'three'], ['four', 'five', 'six']]
Tried
([i[0].split() for i in lst])
but it gives only
[['one', 'two'], ['four', 'five']]
Any ideas how to manage it?
Thanks in advance!
Upvotes: 2
Views: 122
Reputation: 402483
Maybe I'm oversimplifying this, but you can just join and re-split?
>>> [' '.join(x).split() for x in lst]
[['one', 'two', 'three'], ['four', 'five', 'six']]
Or, using the equivalent map
method:
>>> list(map(str.split, map(' '.join, lst)))
[['one', 'two', 'three'], ['four', 'five', 'six']]
Upvotes: 6