Skip to content

Instantly share code, notes, and snippets.

@hickford
Created January 23, 2011 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hickford/792036 to your computer and use it in GitHub Desktop.
Save hickford/792036 to your computer and use it in GitHub Desktop.
test if brackets in string are well-nested
def f(word):
open = 0
for x in word:
if x == "(":
open += 1
elif x == ")":
open += -1
if open < 0:
return False
return open==0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment