Python code for testing well parenthesized expression
Diez B. Roggisch
deets at nospam.web.de
Tue Jul 14 09:07:20 EDT 2009
Jeremy Sanders wrote:
> candide wrote:
>
>> I'm trying to implement in Python a function testing if an expression is
>> well parenthesized. For instance the expression "zx4er(1(er(Yy)ol)ol)ik"
>> is correctly parenthesized but this one "zx(4er(1(er(Yy)ol)ol)ik" is not.
>>
>> My code follows at the end.
>>
>> If you have a better algorithm or a better Python code (I'm a beginner in
>> the Python world), don't hesitate ...
>
> Don't you want to just test that the number of "("s equals the number of
> ")"s or am I missing the point?
Yep, you are:
"())))((("
is certainly not "well parenthized".
Diez
More information about the Python-list
mailing list