Skip to content

Instantly share code, notes, and snippets.

@minimal
Created July 2, 2009 23:07
Show Gist options
  • Save minimal/139774 to your computer and use it in GitHub Desktop.
Save minimal/139774 to your computer and use it in GitHub Desktop.
# http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/
def balanced(s, parens="()[]", swap={')':'(', ']':'['}):
if list(reversed(s[:len(s)//2])) == [swap.get(c) for c in list(s)[len(s)//2:]]:
return all(True for i in s if i not in parens)
return False
def balanced(s, parens="()[]", swap={')':'(', ']':'['}):
return all(True for i in s if i not in parens) if list(reversed(s[:len(s)//2]))\
== [swap.get(c) for c in list(s)[len(s)//2:]] else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment