""" use a stack to check whether parentheses are balanced
"""
import stack
def balanced_delimiters(s: str) -> bool:
    """
    Return whether the delimiters in string s
    are balanced.
    Assume: Only delimiters are brackets, parentheses, braces
    >>> balanced_delimiters("[({])}")
    False
    >>> balanced_delimiters("[({})]]")
    False
    >>> balanced_delimiters("[[]")
    False
    >>> balanced_delimiters("[(1+2){}]")
    True
    >>> balanced_delimiters("(1  + [ 7 - { 8 / 3 ] } )")
    False
    >>> balanced_delimiters("{(1  + [ 7 - { 8 / 3 } ] )")
    True
    """
    st = stack.Stack()
    left_delim = {")": "(", "]": "[", "}": "{"}
    for c in s:
        if c not in "()[]{}":  # ignore none delimiters
            pass
        elif c in "([{":  # left add to the stack
            st.add(c)
        elif not st.is_empty():  # stack has some left brackets
            if left_delim[c] != st.remove():  # remove the delimieter at top
                                            # compare it with its match
                    return False  # right does not match left
        else:
            return False
    return st.is_empty()  # to make sure that no left brackets left

if __name__ == '__main__':
    import doctest
    doctest.testmod()


#assert c in ")]}"
