Every Leg of the Route

Data with PythonMedium+10 XP+10

Every Leg of the Route

A delivery van visits its stops in the order given. Each stop is a position, and every stop has the same number of coordinates (often two, but not always).

A leg is the straight-line trip from one stop to the next: leg 0 goes from stop 0 to stop 1, leg 1 from stop 1 to stop 2, and so on.

Task: write route_summary(stops) returning a dict:

  • "total" — the length of the whole route (every leg added up), rounded to 3 decimal places,
  • "longest_leg" — the number of the longest leg. If two legs tie for longest, give the earlier one.

There are always at least two stops.

Examples

stops = [[0, 0], [3, 4], [3, 10], [0, 6]]
returns {'total': 16.0, 'longest_leg': 1}
stops = [[1, 1], [2, 3], [5, 3]]
returns {'total': 5.236, 'longest_leg': 1}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run