This line of code:
item, self._parent[item] = parent, self._parent[parent]
The problem is this:
parents = [1, 2, 2]
item = 0
parent = parents[item]
item, parents[item] = parent, parents[parent]
print(parents)
prints [1, 2, 2]
But 0's parent should be 2 now.
If you separate them out and do:
parents = [1, 2, 2]
item = 0
parent = parents[item]
parents[item] = parents[parent]
item = parent
print(parents)
This correctly prints [2, 2, 2].
This seems like some complex order of operations issue with multiple assignment in python. I'm using 3.8.8.
This line of code:
The problem is this:
prints
[1, 2, 2]But 0's parent should be 2 now.
If you separate them out and do:
This correctly prints
[2, 2, 2].This seems like some complex order of operations issue with multiple assignment in python. I'm using 3.8.8.