<p dir="ltr">And exec() should give you the willies.  </p>
<div class="gmail_quote">On Nov 17, 2014 10:52 AM, "Joe Shaw" <<a href="mailto:joe@joeshaw.org">joe@joeshaw.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I'd probably iterate over the string and increment a paren counter.  If it ever went < 0, it's unbalanced and bail out. At the end, if it's > 0, it's not properly closed.  This is basically a very lame lexer/parser state machine. Something like:</div><div><br></div><div>for s in strings:</div><div>    paren_level = 0</div><div>    for i, c in enumerate(s):</div><div>        if c == '(':</div><div>            paren_level += 1</div><div>        elif c == ')':</div><div>            paren_level -= 1</div><div>        if paren_level < 0:</div><div>            print "{}: Unbalanced closing paren at pos {}: '{}'".format(s, i, c)</div><div>            break</div><div>    # obviously would be better to track the position of the last open paren</div><div>    if paren_level > 0:</div><div>       print "{}: Unclosed opening paren somewhere".format(s)</div><div><br></div><div>Joe</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 17, 2014 at 10:39 AM, Eric Floehr <span dir="ltr"><<a href="mailto:eric@intellovations.com" target="_blank">eric@intellovations.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><span><div class="gmail_extra">for s in strings:</div></span><div class="gmail_extra">    print(repr(s), s.count('(') == s.count(')'))</div></div></div></div></blockquote><div><br></div></span><div>But that will return true for ")this) isn't balanced( b)ut (says it( is"</div><div><br></div></div></div></div>
<br>_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org" target="_blank">CentralOH@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/centraloh" target="_blank">https://mail.python.org/mailman/listinfo/centraloh</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org">CentralOH@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/centraloh" target="_blank">https://mail.python.org/mailman/listinfo/centraloh</a><br>
<br></blockquote></div>