Creating a list with a recursive function by unpacking multiple dimensional list into one dimensional list

19 Views Asked by At

Having a mutiple dimensional list I want to remove all overlap [] and solve to create a one-dimensional list making the part a recursive function.

The values of the original list are selected arbitrarily: another list must exist within the list.

Output:

Original list:

[[1, 2, 3], [4 [55, 66]], 5, [7, 8]]

Modified list:

[ 1, 2, 3, 4, 55, 66, 5, 7, 8]

What I tried was the following but I'm stuck...

old_list = [[1, 2, 3], [4, [55, 66]], 5, [7, 8]]
new_list = []
for sublist in g:
    for item in sublist:
        new.append(item)

print(old_list)
print(new_list)
0

There are 0 best solutions below