Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

flatten list python

def flatten(L):
    for item in L:
        try:
            yield from flatten(item)
        except TypeError:
            yield item

list(flatten([[[1, 2, 3], [4, 5]], 6]))
>>>[1, 2, 3, 4, 5, 6]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #flatten #list #python
ADD COMMENT
Topic
Name
4+2 =