import itertools
a=[[1, 2, 3], [4, 5, 6]]
flat_list = list(itertools.chain.from_iterable(a))
print(flat_list)
# Output:
[1, 2, 3, 4, 5, 6]
def flatten(x):
if isinstance(x, list):
return [a for i in x for a in flatten(i)]
else:
return [x]
def flatten(t):
return [item for sublist in t for item in sublist]