Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python denest list of anything

l = [1,"bob",[[4,3],[2,1]], ["a","b","c"], np.asarray([1,2,3])]
flatten = lambda *n: (e for a in n for e in (flatten(*a) if isinstance(a, (tuple, list)) else (a,)))
list(flatten(l))
>>> [1, 'bob', 4, 3, 2, 1, 'a', 'b', 'c', array([1, 2, 3])]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #denest #list
ADD COMMENT
Topic
Name
2+8 =