Computer Science

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].

Python

Linear Lists

2 Likes

Answer

def MVisit(Lst):
    max_index = 0
    for i in range(1, len(Lst)):
        if len(Lst[i]) > len(Lst[max_index]):
            max_index = i
    return Lst[max_index]

V = [[2, 6], [3, 10], [15], [23], [1, 8, 15, 22, 29], [14]]

result = MVisit(V)
print(result)

Output

[1, 8, 15, 22, 29]

Answered By

1 Like


Related Questions