Sequence Difference

Source: May 2026, Task 4 (DTU 02002/02003). Study solution — not an official answer key.

Problem

For equal-length lists a and b, the difference is sum(|a[i] - b[i]|).

Write sequence_difference(a, b) returning that float.

Example
>>> sequence_difference([1.2, 2.4, 3.6], [4.2, 0.2, 6.6])
8.2

Approach

Use zip with abs and sum.

Solution

Show solution Hide solution
Solution
def sequence_difference(a, b):
    return sum(abs(x - y) for x, y in zip(a, b))