+ 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 đŸ€—đŸ™đŸ™đŸ™

20th Dec 2021, 5:28 AM
Saba
Saba - avatar
2 Answers
+ 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!
20th Dec 2021, 12:11 PM
Lothar
Lothar - avatar