[CentralOH] 2014-11-14 道場 Scribbles: Injection Attacks

iynaix iynaix at gmail.com
Mon Nov 17 17:11:06 CET 2014


Ah yes, that test case didn't cross my mind. In that case, a running sum of
some kind would be required.

def parens_are_balanced(s):
    _sum = 0
    for c in s:
        if c == '(':
            _sum += 1
        elif c == ')':
            if _sum == 0:
                return False
            _sum -= 1
    return _sum == 0

Jim's first 2 implementations of quantify_parens could be turned into
generators by substituting the outermost square brackets with parens.


Cheers,
Xianyi

On Mon, Nov 17, 2014 at 11:39 PM, Eric Floehr <eric at intellovations.com>
wrote:

> for s in strings:
>>     print(repr(s), s.count('(') == s.count(')'))
>>
>
> But that will return true for ")this) isn't balanced( b)ut (says it( is"
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20141118/854b31f3/attachment.html>


More information about the CentralOH mailing list