”。栈的底部很重要，因为在栈中靠近底部的项是存储时间最长的。最近添加的项是最先会被移除的。这种排序原则有时被称为 LIFO
，后进先出。它基于在集合内的时间长度做排序。较新的项靠近顶部，较旧的项靠近底部。

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():
#一种情况是左括号缺失，栈内没有左括号 balance = False else: if s_dict[s.peek()] == char: s.pop()
#每组成一队括号，栈就弹出一个成员 return s.isEmpty() and balance #最后，所有括号均能匹配,栈应该是空的
print(parChecker('123(((131)))1331')) print(parChecker('([])({})[]'))
print(parChecker('123(((131)))1331')) print(parChecker('([])({})[]')) True True
Process finished with exit code 0

from pythonds.basic.stack import Stack def
baseConverter(decNumber:int,base:int): digits = "0123456789ABCDEF" if base > 16
or base < 2: return decNumber #超出转换范围 remstack = Stack() #储存余数 while decNumber
> 0: rem = decNumber % base #取余数 remstack.push(rem) decNumber = decNumber //
base #向下取整做除法 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