0
I can’t find the error in this code: A sequence of parentheses "(" ")", brackets "[" "]" and keys "{" "}" is said to be balanced if each "open" symbol is "closed" at an appropriate time
For example '([])' is a balanced sequence '([)]' is not balanced '([]' is not balanced ')' is not balanced '' is balanced * If you see a letter/number (or anything other than (){}[]<> the function should ignore instead of giving an error. my code:
def balanceada(string):
pilha = []
for i in string:
if i != '(' or i != '[' or i != '{' or i != '<' or i != ')' or i != ']' or i != '}' or i != '>':
pass
else:
if i == '(' or i == '[' or i == '{' or i == "<":
pilha.append(i)
else:
topo = pilha[-1]
if (i == ")" and topo == "(") or (i == "]" and topo == "[") or (i == "}" and topo == "{") or (i == ">" and topo == "<"):
pilha.pop()
else:
return False
if len(pilha) == 0:
return True
else:
return False
when I run the test: self.assertEqual(balanced('([}[])'),False) Assertionerror: True != False