Skip to content
Advertisement

nested list content does not preserve when appending to a main list

I’m working on a basic program allows me to navigate in a two dimensions grid (for now 3X3), using a function specified with the initial point and all the steps moved on each axis, returning the end point. I want to raise an error if a specific point has been already visited, and I’m trying to do it by logging all previous points. This is my code:

JavaScript

My problem is, I want to reference each point with a nested list inside the main list, but the code above is giving me this result:

JavaScript

When I try to convert it to a nested list, I get:

JavaScript

Instead of simply [[1, 1],[2, 2],[3, 3]], please help!

Advertisement

Answer

This approach basically takes the last appended points from point_logs and adds the new coordinates to it after which it is also appended.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement