I have this string "[1,[2,3],[4,5,6],[7,[8,90],10],[11,120,[13]]]" as an input. How can I convert this string to a list by using recursion or iteration but no imports in Python?
This is what I have tried. This solution only worked for the string "[1,[2,3]]" part of my input.
The expected output is the [1,[2,3],[4,5,6],[7,[8,90],10],[11,120,[13]]]
l = "[1,[2,3],[4,5,6],[7,[8,90],10],[11,120,[13]]]"
def convert(l,out=[],i=0):
while i<len(l)-1:
if l[i] == "]":
return out,i
if l[i] =="[":
out_to_add,index = convert(l[i+1:],[])
out.append(out_to_add)
i+=index
elif l[i]!=",":
out.append(l[i])
i+=1
print(convert(l)[0][0])
edit: NB. this is an assignment and not imports are allowed