From books : Stack ( Sometimes called “ LIFO stack ”) Is an ordered collection of items , Adding and removing new items always happens at the same end . This end is often called “ Top ”. The end corresponding to the top is called “ bottom
”. The bottom of the stack is important , Because the items near the bottom of the stack have the longest storage time . Recently added items are the first to be removed . This ordering principle is sometimes referred to as LIFO
, Last in, first out . It sorts based on the length of time in the set . The newer item is near the top , The older item is near the bottom .

Stack function

Bracket missing detection using stack
from pythonds.basic.stack import Stack s_dict = {"{":"}","[":"]","(":")"} def
parChecker(symbolString): balance = True s = Stack() for char in symbolString:
if char in "{[(": s.push(char) elif char in "}])": if s.isEmpty():
# In one case, the left bracket is missing , There is no left bracket in the stack balance = False else: if s_dict[s.peek()] == char: s.pop()
# Each consists of a set of brackets , A member pops up on the stack return s.isEmpty() and balance # last , All brackets match , The stack should be empty
print(parChecker('123(((131)))1331')) print(parChecker('([])({})[]'))
print(parChecker('123(((131)))1331')) print(parChecker('([])({})[]')) True True
Process finished with exit code 0
Using stack to realize conversion between decimal system and other systems
from pythonds.basic.stack import Stack def
baseConverter(decNumber:int,base:int): digits = "0123456789ABCDEF" if base > 16
or base < 2: return decNumber # Out of conversion range remstack = Stack() # Store remainder while decNumber
> 0: rem = decNumber % base # Take remainder remstack.push(rem) decNumber = decNumber //
base # Divide by rounding down newString = "" while not remstack.isEmpty() : newString =
newString + digits[remstack.pop()] return newString print(baseConverter(25,2))
print(baseConverter(169,16)) 11001 A9 Process finished with exit code 0

©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network