Reputation: 2020
How to unpack a list, which is nested inside another list. Practically to transform this:
l=['aa','bb',['ccc','ddd'],'ee']
to
l=['aa','bb','ccc','ddd','ee']
Upvotes: 0
Views: 366
Reputation: 7592
See this thread and e. g. the solution of elqott
>>> from compiler.ast import flatten >>> l = ['1','2',['3','4'],'5'] >>> flatten(l)
Following your edit
['1', '2', '3', '4', '5'] >>> l = ['aa','bb',['ccc','ddd'],'ee'] >>> flatten(l) ['aa', 'bb', 'ccc', 'ddd', 'ee']
Upvotes: 1