I have this code:
def num(list, target):
index = []
for i in list:
for x in list:
if i + x == target:
index.append(list.index(i))
index.append(list.index(x))
break
print(index)
li = [1, 7, 11, 2, 15]
num(li, 9)
I expected to get [1,3]
, but the result is [1,3,3,1]
. Why?