Score: 0.8264126181602478; Reported for: String similarity
Open both answers

Present in both answers;
Present only in the new answer;
Present only in the old answer;

openList = ["[","{","("]
closeList = ["]","}",")"]
def balance(myStr):
stack= []
for i in myStr:
if i in openList:
stack.append(i)
elif i in closeList:
pos = closeList.index(i)
if ((len(stack) > 0) and (openList[pos] == stack[len(stack)-1])):
stack.pop()
else:
return "Unbalanced"
if len(stack) == 0:
return "Balanced"
print balance("{[()](){}}")

My solution here works for brackets, parentheses & braces

openList = ["[","{","("] closeList = ["]","}",")"] def balance(myStr): stack= [] for i in myStr: if i in openList: stack.append(i) elif i in closeList: pos = closeList.index(i) if ((len(stack) > 0) and (openList[pos] == stack[len(stack)-1])): stack.pop() else: return "Unbalanced" if len(stack) == 0: return "Balanced" print balance("{[()](){}}")

openList = ["[","{","("] closeList = ["]","}",")"] def balance(myStr): stack= [] for i in myStr: if i in openList: stack.append(i) elif i in closeList: pos = closeList.index(i) if ((len(stack) > 0) and (openList[pos] == stack[len(stack)-1])): stack.pop() else: return "Unbalanced" if len(stack) == 0: return "Balanced" print balance("{[()](){}}")

Present in both answers;
Present only in the new answer;
Present only in the old answer;