Main_List = [[[2]], [4, [5, 6, [6], 6, 6, 6], 7]]
Main_List.func() #[2, 4, 5, 6, 6, 6, 6, 6, 7]
import re
def flatten(lst):
return [int(x) for x in re.findall('\d+', str(lst))]
Main_List = [[[2]], [4, [5, 6, [6], 6, 6, 6], 7]]
def flatten(lst):
while lst:
sublist = lst.pop(0)
if isinstance(sublist, list):
lst = sublist + lst
else:
yield sublist
print(list(flatten(Main_List)))
Main_List = [[[2]], [4, [5, 6, [6], 6, 6, 6], 7]]
def flat_list(nested):
return [int(i) for i in str(nested).replace('[', '').replace(']', '').split(', ') if i]
print(flat_list(Main_List))
[2, 4, 5, 6, 6, 6, 6, 6, 7]