我有一个如下所示的输出:
output=[[[], [], [], [1582, 2912, 3109, 5711], []],
[[], [1182, 1432, 2127, 2274, 2613, 3024, 3703, 4723, 5288, 5438], [], []],
[[], [], [], [], [27, 574, 835, 1221, 1388, 1525, 1842, 2070, 2547, 3578, 3798, 3932, 4066, 4157, 4350, 4567, 4709, 5176, 5564, 5744], [], []],
[[], [], [], [], []],
[[]],
[[], []],
[[], [1182, 1432, 2127, 2274, 2613, 3024, 3703, 4723, 5288, 5438], [], [], [1452, 2120, 5628]],
[[3610], []],
[[], [], [], []],
[[3842], []],
[[1566], [3842], []],
[[5182, 5569], [], []],
[[], [3842], [], [], [1452, 2120, 5628]],
[[], [], []],
[[]],
[[], [377, 576, 2682, 3071, 5760], [900, 1723, 2658, 3076], []],
[[], []],
[[], [], [], [], [1452, 2120, 5628]],
[[], [1182, 1432, 2127, 2274, 2613, 3024, 3703, 4723, 5288, 5438], [], []]]
对于输出的每一行,我需要找到一个列表中的数字与该行的另一个列表中的数字的所有可能距离组合。例如,对于行:
[[1566], [3842], []],
我只需要找到距离(1566-3842),但对于行:
[[], [377, 576, 2682, 3071, 5760], [900, 1723, 2658, 3076], []],
我需要找到所有可能的距离组合。有人可以告诉我一个快速的方法吗?非常感谢。
我正在考虑做这样的事情:
>>> dis=[]
>>> for i in range(len(output)):
for j in output[i]:
if any(abs(num-numb) for num in output[i] for numb in output[i+1]):
di=abs(num-numb)
dis.append(di)
我在正确的轨道上吗?