+ 1
How to delete parentheses for an input in python?
I have an input like this: Input: (A - B + C) - (C / (D - E)) I need to delete parentheses and print output like this: Output: A - B + C - (C / (D - E)) Could you please help me write this program? Or give me a hint about how to solve it? Thanks 🤗🙏🙏🙏
2 Respuestas
+ 6
Saba ,
this description works only correct for the first pair of parenthesis starting from left side:
▪︎split the input with the list constructor:
inp = list("(A - B + C) - (C / (D - E))")
this will separate all characters to individual list elements
▪︎then you can use the index method of list to find the first opening parenthesis "(" starting from left side
this will return the index number of the mentioned character.
use this index to delete the character in the list.
▪︎ do the same with the closing parenthesis as mentioned above.
▪︎the last step is to join() the modified list back to a string.
if you need more help, please do a try and post it here.
happy coding and good success!