请写个函数:f(list, d),将数组中距离等于d的所有组合用"x:y" 的格式打印出来,并返回组合的个数, 要求:时间复杂度为O(n)

list=[3,5,8,4,8,7,10], d为list中两个数的距离,距离定义为两个数据差值的绝对值。
请写个函数:f(list, d),将数组中距离等于d的所有组合用"x:y" 的格式打印出来,并返回组合的个数,
要求:时间复杂度为O(n)

def f(l:list,d:int)->int:
    l.sort()
    count = 0
    for i in range(len(l)-1):
        y = d + l[i]
        c = l[i+1:].count(y)
        for _ in range(c):
            print(f'{l[i]}:{y}')
        count += c
    return count

num_list = [3,5,8,4,8,7,10]
print(f(num_list,4))
3:7
4:8
4:8
3
lst=[3,5,8,4,8,7,10]
>>> def f(lst,d):
    res = []
    for i,n in enumerate(lst):
        t = {lst[i]:j for j in lst if abs(n-j)==d}
        if t : res.append(t)
    return res

>>> print(*f(lst,1))
{3: 4} {5: 4} {8: 7} {4: 5} {8: 7} {7: 8}
>>> print(*f(lst,2))
{3: 5} {5: 7} {8: 10} {8: 10} {7: 5} {10: 8}
>>> print(*f(lst,3))
{5: 8} {8: 5} {4: 7} {8: 5} {7: 10} {10: 7}