I wanted to remove elements within brackets, taking a string as input. I initially tried using the following code.
m=input("Enter a string:")
m=list(m)
print(m)
for i in m:
k=m.index(i)
if i=='(':
x=m.index('(')
y=m.index(')')
for k in range(x,y+1,1)
m.remove(m[k])
m="".join(m)
print(m)
But this code didn't remove the elements within brackets. Instead, it removed the brackets and some elements in the first word. I found the following code to be working.
m=input("Enter a string:")
m=list(m)
for i in m:
k=m.index(i)
if i=='(':
x=m.index('(')
y=m.index(')')
del m[x:y+1]
m="".join(m)
print(m)
I am new to python. Though I tried several times, I couldn't find the mistake in the first code and couldn't see why it removed only the brackets though I specified the range correctly. It would be helpful if someone could help me with the same.