Created
February 16, 2018 11:27
-
-
Save loisgh/c3f5af6f893ffe637a7748817755816a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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