You are viewing a single comment's thread. Return to all comments →
slightly cleaner style:
def is_matched(expression): pairs_dict = {'}': '{', ']': '[', ')': '('} stack = [] for char in expression: if char in pairs_dict.values(): stack.append(char) elif char in pairs_dict: if not stack or pairs_dict[char] != stack.pop(): return False return not stack
Seems like cookies are disabled on this browser, please enable them to open this website
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
slightly cleaner style: