1

I got a list [1, [2, [3, [4, [5, [6, [7], 6], 5], 4], 3], 2], 1] and I wanna convert it to a single-dimensional list as the same order as it defined i.e [1,2,3,4,5,6,7,6,5,4,3,2,1]

here is my code, but it is actually not meet my request

list_1 = [1, [2, [3, [4, [5, [6, [7], 6], 5], 4], 3], 2], 1]

def my_solution(lst):
    for index, value in enumerate(lst):
        if isinstance(value, list):

            my_solution(value)

            lst.extend(value)
            del(lst[index])
    return lst


print(my_solution(list_1))

the output is [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7]

Chweng Mega
  • 1,598
  • 1
  • 13
  • 22
  • Related reading: [Recursive generator for flattening nested lists](https://stackoverflow.com/q/11377208/953482) – Kevin Jun 21 '17 at 14:45

0 Answers0