I think the problem is the assignment equation = eqn
. Since eqn
is a list, it is a mutable and thus passed as a reference, when you assign a mutable, the variable actually contains a pointer to that object. This means that equation
and eqn
are the same list.
You should
from copy import deepcopy
equation = deepcopy(eqn)
You need deepcopy
instead of copy
because you have a list of lists, also the inner list needs to be copied.
5
solved Nested list doesn’t work properly