STACK
1. A list containing records of products as L =
[("Laptop", 90000), ("Mobile", 30000), ("Pen", 50),
("Headphones", 1500)] Write the following user-
defined functions to perform operations on a stack
named Product to:
I. Push_element() – To push an item containing
the product name and price of products costing
more than 50 into the stack. Output: [('Laptop',
90000), ('Mobile', 30000), ('Headphones',
1500)]
II. II. Pop_element() – To pop the items from the
stack and display them. Also, display "Stack
Empty" when there are no elements in the
stack. Output: ('Headphones', 1500) ('Mobile',
30000) ('Laptop', 90000) Stack Empty
2. You have a stack named BooksStack that contains
records of books. Each book record is represented
as a list containing book_title, author_name, and
publication_year. Write the following user-defined
functions in Python to perform the specified
operations on the stack BooksStack:
(I) push_book(BooksStack, new_book): This
function takes the stack BooksStack and a
new book record new_book as arguments
and pushes the new book record onto the
stack.
(II) pop_book(BooksStack): This function pops
the topmost book record from the stack and
returns it. If the stack is already empty, the
function should display "Underflow".
(III) peep(BookStack): This function displays the
topmost element of the stack without
deleting it. If the stack is empty, the
function should display 'None'.
3. A list, NList contains following record as list
elements: [City, Country, distance from Delhi] 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.
4. A list contains following record of a customer:
[Customer_name, Phone_number, City] Write the
following user defined functions to perform given
operations on the stack named ‘status’:
(i) Push_element() - To Push an object
containing name and Phone number of
customers who live in Goa to the stack
(ii) (ii) Pop_element() - To Pop the objects from
the stack and display them. Also, display
“Stack Empty” when there are no elements
in the stack.
5. 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: If the dictionary contains the following
data:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eras
er":25} The stack should contain Notebook Pen
The output should be:
The count of elements in the stack is 2