Programming, Data Structures And Algorithms Using Python — Week 4 Programming Assignment | NPTEL | [Jan 2023]

Programming, Data Structures And Algorithms Using Python — Week 4 Programming Assignment | NPTEL Jan 2023 | Answer with Explanation

Computer Bits Daily
1 min readFeb 20, 2023

We have a list of annual rainfall recordings of cities. Each element in the list is of the form (c,r) where c is the city and r is the annual rainfall for a particular year.
The list may have multiple entries for the same city, corresponding to rainfall recordings in different years.

Write a Python function rainaverage(l) that takes as input a list of rainfall recordings and computes the avarage rainfall for each city. The output should be a list of pairs (c,ar) where c is the city and ar is the average rainfall for this city among the recordings in the input list. Note that ar should be of type float. The output should be sorted in dictionary order with respect to the city name.
Here are some examples to show how rainaverage(l) should work.

https://www.computerbitsdaily.com/2023/02/Programming-Data-Structures-Algorithms-Using-Python-week4-Programming-Assignment.html

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Computer Bits Daily
Computer Bits Daily

Written by Computer Bits Daily

Learning Computer skills and Computer technology by learning and sharing

No responses yet

Write a response