Skip to content

Instantly share code, notes, and snippets.

@prithajnath
Created August 22, 2017 19:56
Show Gist options
  • Save prithajnath/f81cef022d53a7da13a398573a79e2b7 to your computer and use it in GitHub Desktop.
Save prithajnath/f81cef022d53a7da13a398573a79e2b7 to your computer and use it in GitHub Desktop.
pairs = {")":"(","}":"{","]":"["}
stack = []
x = raw_input()
balanced = True
for i in x:
if i in pairs.values():
stack.append(i)
else:
top = stack.pop()
if top == pairs[i]:
continue
else:
balanced = False
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment