1.
Write the definition of a user-defined function `push_str (S)` which accepts a list of strings
in a parameter `S` and pushes all those strings which are having at least one vowel in it from
the list `S` into a Stack named `Vowel_String`.
Write function pop_String() to pop the topmost string from the stack and returns it. If the
stack is already empty, the function should display "Empty".
Write function Disp_String() to display all element of the stack without deleting them. If the
stack is empty, the function should display 'None'.
2. You have a stack named ProductStack that contains records of Products. Each Product record
is represented as a list containing Product_name, Product_Price and Brand. Write the
following user-defined functions in Python to perform the specified operations on the stack
ProductStack:
push_Product(ProductStack, new_Product): This function takes the stack ProductStack and
a new product record new_Product as arguments and pushes the new Product record onto
the stack.
pop_Product(ProductStack): This function pops the topmost Product record from the stack
and returns it. If the stack is already empty, the function should display "Underflow".
peep(ProductStack): This function displays the topmost element of the stack without
deleting it. If the stack is empty, the function should display 'None'.
3. A dictionary, EmpRec contains the records of Employees in the following pattern:
{Name:[Salary, Bonus]}, i.e., Name as the key and Dept and Salary in the form of list as the
value. Write the following user-defined functions in Python to perform the specified
operations on the stack named EMP.
Push_Emp(EmpRec): it takes the dictionary as an argument and pushes the Name of the
dictionary into the stack named EMP of those employee whose Salary+Bonus is more than 5000
For Example: if the dictionary EmpRec contains the following data:
EmpRec ={ 'Ashish':[2400,790], 'Vidyun' :[5900,800], 'Disha':[4000,790], 'Sahil' :[3500,2800]}
Thes Stack EMP Should contain: ['Vidyun', 'Sahil']
Pop_Emp(): It pops all the element from the stack and displays them. Also, the function
should display “Employee is Empty” when there are no elements in the stack.
4. A list, FList contains the following record as list elements: [Fname, Type, Price ] 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 food.
Push_element(FList): It takes the nested list as an argument and pushes a list object
containing name of the food and Type, whose price is more that 500.
Pop_element(): The function should pop all the elements from the stack and displays them.
Also, the function should display “Food Empty” when there are no elements in the stack.
5. Write the definition of a function POP_PUSH(LPop, LPush, N) in Python. The (3)
function should Pop out the last N elements of the list LPop and Push them
into the list LPush. For example :
If the contents of the list LPop are [10, 15, 20, 30] And value of N passed
is 2, then the function should create the list LPush as [30, 20] And the list LPop should
now contain [10, 15]
6. 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) Pop_element() - To Pop the objects from the stack and display them. Also, display “Stack
Empty” when there are no elements in the stack.
(iii) Peak_element(): This function displays the topmost element of the stack without deleting it. If
the stack is empty, the function should display 'None'.
A list, items contain the following record as list elements [itemno, itemname,stock]. Each of these
records are nested to form a nested list.Write the following user defined functions to perform the
following on a stack reorder .
i. Push(items)- it takes the nested list as its argument and pushes a list object containing itemno and
itemname where stock is less than 10
ii. Popitems() -It pops the objects one by one from the stack reorder and also displays a message ‘Stack
empty’ at the end.