How to delete parentheses for an input in python? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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