Skip to content

Stacks and queues · routine

Balanced brackets

Write balanced(text): True if every (, [ and { is closed by the right bracket in the right order. Other characters are ignored.

"([]{})" is balanced; "([)]" is not.

Run adds print(balanced("([)]")) after your code, to try it.

Stuck on the idea rather than the code? The Stacks and queues lesson walks through it.