0

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']
B.Kocis
  • 1,954
  • 20
  • 19
  • possible duplicate of [Flatten (an irregular) list of lists in Python](http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python) – embert Mar 09 '14 at 18:13

1 Answers1

1

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']
Community
  • 1
  • 1
embert
  • 7,336
  • 10
  • 49
  • 78