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
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 rain average(l) that takes as input a list of rainfall recordings and computes the average 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.
Step by Step Solution
3.31 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
Python Programming Knowledge required to do this Program Indexing Tuple List Dictionary functions ...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started