You are viewing a single comment's thread. Return to all comments →
More Pythonic:
def is_matched(expression): pairs = {'{' : '}', '[' : ']', '(' : ')'} sk = [] for c in expression: if c in pairs: sk.append(pairs[c]) elif sk and c == sk[-1]: sk.pop() else: return False return not sk
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
More Pythonic: