Question: This is the code that needs programming def sum_of_list_of_lists(list_of_lists): # FIXME (see instructions) pass # you can remove this line when you're done def average_of_list_of_lists(list_of_lists):

This is the code that needs programming

def sum_of_list_of_lists(list_of_lists): # FIXME (see instructions) pass # you can remove this line when you're done

def average_of_list_of_lists(list_of_lists): # FIXME (see instructions) pass # you can remove this line when you're done

def weighted_sum_of_list_of_lists(list_of_lists, weights): # FIXME (see instructions) pass # you can remove this line when you're done

This is the instructions

Three functions to implement in this assignment:

1) sum_of_list_of_lists()

The function's parameter is list of lists, not just a list. For example, the function could be called with [[1, 2, 3], [1], [1, 2]] as argument, and in this case the function would return 10 (1+2+3+1+1+2). The function should return 0 when the list is empty.

2) average_of_list_of_lists()

Similar to the first function, the function's parameter is a list of lists. It computes the average instead of just computing the sum. Using the example above, the function would return 1.66667 (10 divided by 6).

3) weighted_sum_of_list_of_lists()

That function takes 2 parameters. The first one is the list of lists (as in the first 2 functions) and the second one is a list of weights. Note that the second parameter is NOT a list of lists, it is just a list of numbers but you can assume it has as many elements as there are elements in the first parameter (the list of lists).

For example, one could call:

 
 

numbers = [[2], [8, 6]]

 

weights = [1, 1, 10]

 

result = weighted_sum_of_list_of_lists(numbers, weights)

 

print("Weighted sum is", result)

The weighted sum in that example would be 2 * 1 + 8 * 1 + 6 * 10, i.e. it would be equal to 70.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!