Pairs with the smallest difference
items is a list of at least two distinct whole numbers. Write closest_pairs(items)
that returns every pair [a, b] with a < b whose difference is the smallest difference
between any two values, ordered by a.
closest_pairs([4, 2, 1, 3]) -> [[1, 2], [2, 3], [3, 4]]
closest_pairs([1, 3, 6, 10, 15]) -> [[1, 3]]
The point is to practise "sort first": once sorted, the closest pairs are neighbours.
def closest_pairs(items):
...