Stack - Jupyter Notebook
Stack - Jupyter Notebook
1 main()
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
1. Push
2. Pop
3. Display
4. Exit
Enter your choice : 4
Adding Peek and Display Functions
In [8]:
1 main()
1. Push
2. Pop
3. Display
4. Peek
5. Exit
1. Push
2. Pop
3. Display
4. Peek
5. Exit
1. Push
2. Pop
3. Display
4. Peek
5. Exit
1. Push
2. Pop
3. Display
4. Peek
5. Exit
1. Push
2. Pop
3. Display
4. Peek
5. Exit
1. Push
2. Pop
3. Display
4. Peek
5. Exit
Enter
In [12]:
your choice : 2
Dhoni was popped.
1 S = []
2 1.
defPush
PushFromList(S, L):
3 2. Popfor item in L:
4 3. Displayif item%3==0 and item%5==0:
5 4. Peek S.append(item)
6 5. Exit
7 def PopAndDisplay():
8
Enter while
your True:
choice : 3
9
Gill <-- TOP try:
10
Jadeja item = S.pop()
11
Axar print(item)
S12Bharat except:
13
Sanju samson print("No more elements")
14 break
1. Push
2. Pop
In [13]:
3. Display
4. Peek
1 marks = [15,20,30,45,50,60]
5. Exit
1. Push
2. Pop
3. Display
4. Peek
In [16]:
5. Exit
1 PopAndDisplay()
Enter your choice : 5
60
45
30
15
No more elements
2. define a function Push to add a list containing book number and book name to a stack
In [17]:
1 def Push(S):
2 bno = int(input("Enter book Number : "))
3 bname = input("Enter book name : ")
4 item = [bno,bname]
5 S.append(item)
6 print("Pushed")
In [18]:
1 S = []
In [20]:
1 Push(S)
In [21]:
1 Push(S)
In [22]:
1 Push(S)
1 print(S)
In [24]:
1 def printSelect(S):
2 for item in S:
3 if item[1][0].lower()=='d':
4 print(item)
In [25]:
1 printSelect(S)
[2, 'DEF']
In [ ]: