Stack Practice Questions
Stack Practice Questions
4 Write a function in Python, Push(book) where, book is a dictionary containing the details of a
book in form of {bookno : price}.
The function should push the book in the stack which have price greater than 300. Also display
the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Dbook={"Python":350,"Hindi":200,"English":270,"Physics":600, “Chemistry”:550}
The stack should contain
Chemistry
Physics
Python
The output should be:
The count of elements in the stack is 3
5 Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and
delete a Book from a List of Book titles, considering them to act as push and pop
operations of the Stack data structure.
7 Write a function in python, pushme (stock, item) and popme(stock ) to add a new
item and delete an item from the stock, considering them to act as push and pop
operations of the stack.
8 Pramod has created a dictionary containing EMPCODE and SALARY as key value pairs of 5
Employees of Parthivi Constructions.
Write a program, with separate user defined functions to perform the following operations:
● Push the keys (Employee code) of the dictionary into a stack, where the corresponding value
(Salary) is less than 25000.
● Pop and display the content of the stack. For example: If the sample content of the dictionary is
as follows:
EMP={"EOP1":16000, "EOP2":28000, "EOP3":19000, "EOP4":15000, EOP5":30000}
3
The output from the program should be: EOP4 EOP3 EOP1
9 Write a function in Python PushBook(Book) to add a new book entry as book_no and book_title
in the list of Books , considering it to act as push operations of the Stack data structure.
Write a function in Python PopBook(Book), where Book is a stack implemented by a list of
books. The function returns the value deleted from the stack
11 Mr.Ajay has created a list of elements. Help him to write a program in python with functions,
PushEl(element) and PopEl(element) to add a new element and delete an element from a List of
element Description, considering them to act as push and pop operations of the Stack data
structure
. Push the element into the stack only when the element is divisible by 4.
For eg:if L=[2,5,6,8,24,32]
then stack content will be 32 24 8
15 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 25.
Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data
Ditem = {“Rubber”:5, "Pencil":5, "Pen":30, "Notebook": 60, "Eraser":5, “Watch”: 250}
The stack should contain
Pen
Notebook
Watch
The output should be:
The count of elements in the stack is 3