You are viewing a single comment's thread. Return to all comments →
Even more pythonic
def is_matched(expression): pairs = {'{' : '}', '[' : ']', '(' : ')'} sk = [] for c in expression: if c in pairs: sk.append(pairs[c]) elif not sk or c != sk.pop(): return False return not sk
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 →
Even more pythonic