peek as we said earlierwe could also add peek method this will just return the top of the stack without removing it from the stackallowing us to look at the top element without changing the stack itself this operation is very straightforward if there is top elementreturn its dataotherwise return none (so that the behavior of peek matches that of pop)def peek(self)if self top return self top data elsereturn none bracket-matching application now let us look at an example of how we can use our stack implementation we are going to write little function that will verify whether statement containing brackets--([or {--is balancedthat iswhether the number of closing brackets matches the number of opening brackets it will also ensure that one pair of brackets really is contained in anotherdef check_brackets(statement)stack stack(for ch in statementif ch in ('{''[''(')stack push(chif ch in ('}'']'')')last stack pop(if last is '{and ch is '}'continue elif last is '[and ch is ']'continue elif last is '(and ch is ')'continue elsereturn false if stack size return false elsereturn true our function parses each character in the statement passed to it if it gets an open bracketit pushes it onto the stack if it gets closing bracketit pops the top element off the stack and compares the two brackets to make sure their types matchshould match )should match ]and should match if they don'twe return falseotherwise we continue parsing