May-02-2020, 03:52 PM
I tried to flatten list.I have nested list and i want all iterables of that nested list in one list without any nested list. Itried with itertool.chain and also with recursive function.
import itertools a = [[1,2,3], [4,7,8],9] b = list(itertools.chain(a)) print(b)
def flatten(list): a=[] for i in list: if type(i) == list: flatten(i) else: a.append(i) return a b = [[1,2,3], [4,7,8],9] c = flatten(b) print(c)I still get nested list in result. No changes