def par_checker_ext(line): """Check if parentheses & brackets are balanced""" stack = Stack() balanced = True i = 0 while i < len(line) and balanced: symbol = line[i] if symbol in "( { [ <": stack.push(symbol) else: if stack.is_empty(): balanced = False else: sym2 = ( symbol.replace(")", "(") .replace("]", "[") .replace("}", "{") .replace(">", "<") ) if sym2 == stack.peek(): stack.pop() else: balanced = False i = i + 1 return balanced and stack.is_empty()
my_list.add(54) print(my_list.size()) print(my_list.search(93)) print(my_list.search(100)) # Alternative implementation from the pythonds3 library # -> sudo pip3 install pythonds3 from pythonds3.basic import Stack s = Stack() print(s.is_empty()) s.push(4) s.push("dog") print(s.peek()) s.push(True) print(s.size()) print(s.is_empty()) s.push(8.4) print(s.pop()) print(s.pop()) print(s.size()) m = Stack() m.push("x") m.push("y") m.push("z") while not m.is_empty(): print(m.peek())