Junior — Senior
Calculating the average year of car manufacture by region
livecode
Task condition
There is a class Car containing a license plate number and the year of manufacture of the car. The task is to calculate the average year of manufacture for each region, using the list cars.
class Car:
def __init__(self, number: str, year: int):
self.number = number
self.year = year
cars = [
Car("a121mm16", 2016),
Car("c313xx16", 2011),
Car("b777xx777", 2007),
Car("a123xx01", 2012),
Car("c888xx777", 2022),
Car("b123xx47", 2002),
]
The task involves parsing the car number to obtain the region, grouping cars by region, and calculating the average year of manufacture in each group.