Added lecture 2026113
This commit is contained in:
parent
be356ccb59
commit
5b630435ae
27 changed files with 738 additions and 0 deletions
34
lecture20261103/lists02/lists04-pop.py
Normal file
34
lecture20261103/lists02/lists04-pop.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/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))
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue