def select_d(list,d): # list = sorted(list) sum = {} for i in list: if i+d in list: sum[i] = i+d return sum list = [1,2,3,4,5,6,7,8,9,0,1213,12,31,2,13,21,21,221,11,10] print(select_d(list,2)) 运行结果: {1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9, 8: 10, 9