方法一
nums = [1,2,5,6,4,3]
target = 8
for i, n in enumerate(nums):
if target-n in nums[i+1:]:
print([i, nums[i+1:].index(target-n) + i+1])
方法二
target = 4
lis = [1,2,5,6,4,3,6,2]
len_lis = len(lis)
[[subscript1,subscript2] for subscript1,i in enumerate(lis) for subscript2 in range(subscript1, len_lis) if i+lis[subscript2]==target]
Out[53]: [[0, 5], [1, 1], [1, 7], [7, 7]]