l = [1, 13, 2, 1, 7, 7]
def fn(lst):
ll = []
for i in range(len(lst)-1):
if (14-lst[i]) not in lst[i+1:]: #删除两个元素的和为14
ll.append(lst[i])
return ll
print(fn(l))
结果:
[2, 1]
l = [1, 13, 2, 1, 7, 7]
def fn(lst):
ll = []
for i in range(len(lst)-1):
if (14-lst[i]) not in lst[i+1:]: #删除两个元素的和为14
ll.append(lst[i])
return ll
print(fn(l))
结果:
[2, 1]