STACK PROGRAM
STACK PROGRAM
1.
Each of these records are nested together to form a nested list. Write the following user
defined functions in Python to perform the specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument and pushes a list object
containing name of the city and country, which are not in India and distance is less than
3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays them. Also, the function
should display “Stack Empty” when there are no elements in the stack.
['Naypyidaw', 'Myanmar'],
['Dubai', 'UAE'],
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty
Ans:
2.
Write a function in Python, Push(SItem) where , SItem is a dictionary containing the details
of stationary items– {Sname:price}.
The function should push the names of those items in the stack who have price greater than
75. Also display the count of elements pushed into the stack.
For example:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
Notebook
Pen
The output should be:
Ans:
stackItem=[]
def Push(SItem):
count=0
for k in SItem:
if (SItem[k]>=75):
stackItem.append(k)
count=count+1
-------------