from itertools import chain def merge flat_list for sublist in for ite

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from itertools import chain
def merge(l):
flat_list = []
for sublist in l:
for item in sublist:
flat_list.append(item)
return flat_list
def merge2(lst2):
return list(chain(*lst2))
def merge3(lst, res=[]):
for el in lst:
merge(el) if isinstance(el, list) else res.append(el)
return res
a = [1,2,3,[4,[5,5]]]
b = [4]
c = []
d = [1,2,3]
# need r = [1,2,3,4,5,5,4,1,2,3]
print(a)
print(b)
print(c)
print(d)
r = merge([a,b,c,d])
print(r)