I have text like that :
Proxy='ab,cd(ef,gh),ij,kl(mn(op,kr),st),uv'
The expected result would be a nested list in order to create a nary tree representation of the text, so:
ExpectedResult=['ab','cd',['ef','gh'],'ij','kl',['mn',['op','kr'],'st'],'uv']
My try:
temp=[]
stack=[]
comma=[]
op=[]
cl=[]
n=(len(test))
for idx in range(n):
if test[idx] == ',' and not op and not cl and not comma:
stack.append(test[0:idx])
comma.append(idx)
elif test[idx] == ',' and op and not cl and not comma:
temp.append(test[op.pop()+1:idx])
comma.append(idx)
elif test[idx] == ',' and not op and cl and not comma:
if len(test[cl[0]+1:idx]) > 1:
stack.append(test[cl.pop()+1:idx])
comma.append(idx)
else:
cl.pop()
comma.append(idx)
elif test[idx] == ',' and not op and not cl and comma:
stack.append(test[comma.pop():idx])
comma.append(idx)
elif test[idx] == '(' and not op and not cl and comma:
stack.append(test[comma.pop()+1:idx])
op.append(idx)
elif test[idx] == '(' and op and not cl and comma:
temp.append(test[comma.pop()+1:idx])
op.pop()
op.append(idx)
elif test[idx] == ')' and not op and not cl and comma:
temp.append(test[comma.pop()+1:idx])
stack.append(temp)
temp=[]
cl.append(idx)
elif test[idx] == ')' and op and not cl and not comma:
temp.append([test[op.pop()+1:idx]])
cl.append(idx)
elif test[idx] == ')' and not op and not cl and comma:
temp.append(test[comma.pop()+1:idx])
stack.append(temp)
temp=[]
cl.append(idx)
I have found very interesting things here
But this method will return a list of char and I want to join words (not 'a','b' but 'ab') and most of all I do not understand the syntax (and so the function) of the push function.