[pyar] [OT] - Checkeando parentesis balanceados.

Juan BC jbc.develop en gmail.com
Vie Jun 18 13:47:50 ART 2010


El 18/06/10 13:45, Alejandro Santos escribió:
> print balanceau(")(")

el mio funca

si =  "((())()())"
no= ")()()(())"

def balanceado(string):
     stack = []
     for c in string:
         if c == ")" and stack and stack[-1] == "(":
             stack.pop()
         else:
             stack.append(c)
     return not len(stack)

print si, balanceado(si)
print no, balanceado(no)
print ")(", balanceado(")(")



More information about the pyar mailing list