Given some number n, I want to produce a list of size n where the following example shows how the n'th element in the list should be:
- For n=0: return
[]
- For n=1: return
[[]]
- For n=2: return
[[],[[]]]
- For n=3: return
[[], [[]], [[], [[]]]
Basically it takes the precedent lists and append them into a new list.
I've tried the following:
def magic_list_helper(n, lst):
if n == 0:
return lst
if n == 1:
lst.append([])
return magic_list_helper(n-1,lst)
if n > 1:
magic_list_helper(n-1, lst)
new_list = []
new_list.append(lst[n - 2])
lst.append(new_list)
return lst
but for n=3 I get [[], [[]], [[[]]]]
.