I am trying to remove everything between curly braces in a string, and trying to do that recursivesly.
And I am returning x
here when the recursion is over, but somehow the function doit
is returning None
here. Though printing x
within the def prints the correct string.
What am I doing wrong?
strs = "i am a string but i've some {text in brackets} braces, and here are some more {i am the second one} braces"
def doit(x,ind=0):
if x.find('{',ind)!=-1 and x.find('}',ind)!=-1:
start=x.find('{',ind)
end=x.find('}',ind)
y=x[start:end+1]
x=x[:start]+x[end+1:]
#print(x)
doit(x,end+1)
else:
return x
print(doit(strs))
output:
None
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…