I have a list of coordinates (x and y like this: coordinates = [[1, 2], [2, 3]]
but much bigger) that updates every iteration (appends new list). So I need to search if current_pos
(which is also a list like [4, 10]
) is in coordinates
. Here is my snippet of code:
for move in range(len(movement_string)):
# ...
# code changes current_pos
# ...
if current_pos in coordinates:
fail = True
failed_move = move + 1
break
else:
coordinates.append(current_pos)
It works pretty fine with small lists, but it takes too long time for big lists with 10.000 - 1.000.000 items. I think the problem is in searching through list, because as it becomes bigger, the time it uses becomes also longer.