Skip to content

Instantly share code, notes, and snippets.

@loisgh
Created February 16, 2018 11:27
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 loisgh/c3f5af6f893ffe637a7748817755816a to your computer and use it in GitHub Desktop.
Save loisgh/c3f5af6f893ffe637a7748817755816a to your computer and use it in GitHub Desktop.
import Queue
def matching_parens(in_list):
paren_q = Queue.Queue()
for item in in_list:
if item in ('(','['):
paren_q.put(item)
elif item == ')':
check = paren_q.get()
if check == '(':
continue
else:
return False
elif item == ']':
check = paren_q.get()
if check == '[':
continue
else:
return False
if paren_q.qsize():
return False
else:
return True
def main():
in_list = ['(','(',')']
print matching_parens(in_list)
in_list = ['(','(',')',')']
print matching_parens(in_list)
in_list = ['(','[','(',')',']',')']
print matching_parens(in_list)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment