Answers for "convert nested list to single list python"

2

list of lists to single list python

flat_list = [item for sublist in t for item in sublist]
Posted by: Guest on August-03-2021
0

convert 2 level nested list to one level list in python

>>> from collections import Iterable
>>> def flat(lst):
...     for parent in lst:
...         if not isinstance(i, Iterable):
...             yield parent
...         else:
...             for child in flat(parent):
...                 yield child
...
>>> list(flat(([1,[2,2,2],4]))
[1, 2, 2, 2, 4]
Posted by: Guest on May-04-2020

Code answers related to "convert nested list to single list python"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language