2025faCSE160/bigos/lecture20251007/lists02/lists04-pop.py

34 lines
942 B
Python

#!/usr/bin/python3
# List operating as a stack.
dogNames = [ "harry", "Shenanigans","katrina","Tanner","Yukon Jack", "Colorado","Mandy"]
dogNames2 = ["Oscar", "Rusty"]
firstNames = ["edward","david", "Bob","mary","alice"]
intList = [7, 2, 12, 18, 16, 21]
primeList = [1, 2, 3, 7, 11, 13, 17, 19]
txtList = ["7", "2", "12", "18", "16", "21"]
print("pop() can be used to implement a stack. A stack is a last in first out")
print(" (LIFO) structure used in some program logic.")
print (dogNames," length = ",len(dogNames))
dName = dogNames.pop()
print(f"Popped {dName:s}")
print (dogNames," length = ",len(dogNames))
dName = dogNames.pop()
print(f"Popped {dName:s}")
print (dogNames," length = ",len(dogNames))
dName = dogNames.pop()
print(f"Popped {dName:s}")
print (dogNames," length = ",len(dogNames))
print("\n\n")
print("There is no push but we can append")
dogNames.append("Colorado")
print (dogNames," length = ",len(dogNames))