Codington
0 of 6 problems solved • 0%

Exercise prompt

Find the Leading Lines

A useful report separates measuring from selecting. First collect totals for every line; then find the maximum and collect all the lines sharing it.

Example

A school wants every room tied for the smallest class size.

class_sizes = {"Pine": 18, "Elm": 16, "Oak": 16} smallest = min(class_sizes.values()) rooms = [name for name, size in class_sizes.items() if size == smallest] print(sorted(rooms)) # ['Elm', 'Oak']

The class sizes have already been calculated. For a trip log, first build the totals from the records. An empty log has no extreme value.

Your task

Return an alphabetically sorted list of the lines with the greatest total kilometers. Each trip is a dictionary with line and nonnegative km. Return an empty list for an empty timetable.

trips = [{"line": "B", "km": 5}, {"line": "A", "km": 2}, {"line": "A", "km": 3}] leading_lines(trips) # ["A", "B"]