Solution Review: Check Whether the Brackets are Balanced
This review explains the solution for the "balanced brackets" exercise.
We'll cover the following...
Solution
Press + to interact
def check_balance(brackets):check = 0for bracket in brackets:if bracket == '[':check += 1elif bracket == ']':check -= 1if check < 0:breakreturn check == 0bracket_string = '[[[[]]'print(check_balance(bracket_string))
Explanation
The solution relies on the value of the check
variable declared at line 2, which is updated in each iteration.
At ...