23Balanced Brackets

    Mediumstacksstrings

    Write is_balanced(text) that returns True if every bracket (), [], {} in text is closed by the matching kind, in the right order.

    Other characters are ignored. "(a[b]{c})" is balanced; "(]" and "([)]" are not.

    Examples

    Example 1
    >>> is_balanced('(a[b]{c})')
    True
    Example 2
    >>> is_balanced('([)]')
    False

    Run examples checks the 2 examples above. Submit runs all 8 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write is_balanced in the editor, then run the examples. Use print() freely: its output is shown for each test.