Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python flatten everything in list of list

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 #flatten #list #list
ADD COMMENT
Topic
Name
8+1 =