I think your problem is in the last few lines:
for i in range(len(tuples)):
for x in range(len(tuples[i][1])):
[...]
for neighbor in neighbors:
for i in range(len(neighbor)-1): #<- HERE
[...]
Your outer loop is iterating over the index of tuples and stores this index in the variable i
. The nested loop at the end overwrites this variable with another value, which is certainly not what you want.
1
solved List contents changing with each iteration