| f | from itertools import cycle, islice | f | from itertools import cycle, islice | 
            |  |  |  |  | 
            | n | def speed(distances, checkpoints, durations): | n | def speed(path, stops, times): | 
            |  | checkpoint_cycle = cycle(checkpoints) |  | stops_cycle = cycle(stops) | 
            |  | distance_iter = iter(distances) |  | path_iter = iter(path) | 
            |  | duration_iter = iter(durations) |  | time_iter = iter(times) | 
            |  | while True: |  | while True: | 
            | n | checkpoint_count = next(checkpoint_cycle) | n | stop_count = next(stops_cycle) | 
            |  | segment_distance = sum(islice(distance_iter, checkpoint_count)) |  | distance = sum(islice(path_iter, stop_count)) | 
            |  | if segment_distance == 0: |  | if distance == 0: | 
            |  | break |  | break | 
            | t | time_taken = next(duration_iter) | t | time_spent = next(time_iter) | 
            |  | yield (segment_distance / time_taken) |  | yield (distance / time_spent) |