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 š¤ššš
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!