Why would these two lines of code do anything differently from each other?
visited_with_path.append(deep_copy(get_path_to_point(from_point)).append(point))
and
x = deep_copy(get_path_to_point(from_point))
x.append(point)
visited_with_path.append(x)
I just spent a whole lot of time debugging until I tried making the above change (from first to second), and although it fixed the problem, I have no idea why. They seem like they should have identical functionality.
If it helps, visited_with_path is a list of lists of points, deep_copy makes a deep copy of this list of lists, get_path_to_point inputs a point and returns a list of points, and from_point and point are just points.
Any thoughts?
.appendis in-place, so returnsNoneappendreturned a reference to the list being appended to, that one-liner is far too unreadable to be recommended. Plus, different people might assume different things: I would assumeappendwould return a reference to the list so that you could append multiple items at a time; you assume it returns a reference to the time being appended.