I am creating code that calculates neighbor coordinates to passed coordinate.
I have list of lists with "directions" I want move to, first number is X-value, second number is Y-value.
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
Then I have a function to calculate new coordinates and store them in a list "results"
results = []
def NeighborsFinder(coordinate):
originalCoordinate = coordinate
for x in range(0, len(directions)):
coordinate[0] += directions[x][0]
coordinate[1] += directions[x][1]
results.append(coordinate)
print(coordinate)
coordinate = originalCoordinate
Example: if I pass coordinate [2, 3]
Then correct output should be list with coordinates: [2, 4] [2, 2], [3, 3], [1, 3]
Well but what happens to me is that its adding +1, but not substracting -1 so my output look like this: [2, 4], [2, 3], [3, 3], [2, 3].