File - 2102217671 - 1686193757 - D.S Part 5
File - 2102217671 - 1686193757 - D.S Part 5
File - 2102217671 - 1686193757 - D.S Part 5
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.
7) Julie has created a dictionary containing names and marks as key value pairs of
6 students. Write a program, with separate user defined functions to perform
the following operations:
● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
● Pop and display the content of the stack. For example: If the sample content
of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be: TOM ANU BOB OM
8) Alam has a list containing 10 integers. You need to help him create a program
with separate user defined functions to perform the following operations based
on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack. For Example: If the sample Content
of the list is as follows: N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38] Sample
Output of the code should be: 38 22 98 56 34 12
9) Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers
and n is a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2 Output Arr =
[30,40,12,11,10,20]
10) Write a function in Python PUSH(Arr), where Arr is a list of numbers. From
this list push all numbers divisible by 5 into a stack implemented by using a
list. Display the stack if it has at least one element, otherwise display
appropriate error message.
OR
Write a function in Python POP(Arr), where Arr is a stack implemented by a
list of numbers. The function returns the value deleted from the stack.