Skip to content
Advertisement

Calculate the average of list of lists based on two elements in the list?

I have the following list:

JavaScript

I want to calculate the average of the items which have the same “first and the second elements”. E.g., from the below example, I want to take the average of the elements which have ‘5’ and ‘1’ in the first two elements of the list. So, my desired output should be like this:

JavaScript

If I have only two items in the lists like:

JavaScript

I could easily calculate the average by the below code:

JavaScript

Advertisement

Answer

see below

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement