runtime
108 / 500
question 108 String Algorithms · medium

Are the brackets balanced?

A code editor underlines a line when its brackets don't match. Brackets are (), [] and {}: every opening bracket must be closed by the same kind, and pairs must nest, so ([)] is wrong. All other characters are ignored.

Functionbalanced(text)
ReturnsTrue if every bracket is closed by the right kind in the right order, otherwise False
Examples
callbalanced('[1, (2, 3)]')returnsTrue
callbalanced('([)]')returnsFalse
callbalanced('{"a": [1, 2]}')returnsTrue

Loading your progress…

Are the brackets balanced? — Python practice · Runtime