Data Structure - 1 : Linear List  || Type C || Sumita arora || Class 12 || Computer Science || Solution



Q1. Write a program that uses a function called find_in_list( ) to check for the position of the first occurrence of v in the list

passed as parameter (Ist) or-1 if not found. The header for the function is given below:

def find_in_set (lst, v ):
""" lst - a list
v - a value that may or may not be in the list """





Q2. Implement the following function for a linear list, which find outs and returns the number of unique elements in the list

def unique(lst):
"""passed parameter 1st is a list of integers (could be empty). """

After implementing the above function, test it with following lists and show the output produced by above function along with

the reason for that output.

(i) Ist [ ]
(ii) Ist = [1, 2, 3]
(iii) Ist = [1, 2, 2]
(iv) Ist = [1, 2, 2, 3, 3]






Q3. Use a list comprehension to create a list, CB4. The comprehension should consist of the cubes of the numbers 1 through

10 only if the cube is evenly divisible by four. Finally, print that list to the console.
Note that in this case, the cubed number should be evenly divisible by 4, not the original number.





Q4. Take two lists, say for example these two:

a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

and write a program that returns a list that contains only the elements that are common between the lists (without duplicates).

Make sure your program works on two lists of different sizes. Write this in one line of Python using at least one list

comprehension. Run the complete program and show output.






Q5. Suppose we have a list V where each element represents the visit dates for a particular patient in the last month. We want

to calculate the highest number of visits made by any patient. Write a function MVisit(Lst) to do this.

A sample list (V) is shown below:
V = [ [2, 6], [3, 10], [15], [23], [ 1, 8, 15, 22, 29], [14] ]
For the above given list V, the function MVisit() should return the result as [ 1, 8, 15, 22, 29 ]




Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post