The function below takes a single parameter number_list which is a list that can contain integers and floats. Complete the function to return the integer from the provided list that is the largest. There are two recommended approaches for this function. You could either filter out just the integers and use Python's built-in max function, or you could use the find best pattern and only consider list elements that are integers as potentially being the best.

Respuesta :

Answer:

  1. def getLargest(number_list):
  2.    new_list = []
  3.    for x in number_list:
  4.        if(isinstance(x, int)):
  5.            new_list.append(x)
  6.    largest = max(new_list)
  7.    return largest  

Explanation:

Firstly, create a function getLargest() that take one input parameter, number_list.

The function will filter out the float type number from the list by using isinstance() method (Line 5). This method will check if a current x value is an integer. If so, the x value will be added to new_list.

Next, use Python built-in max function to get the largest integer from the new_list and return it as output.

ACCESS MORE