Python function is changing the value of my input, and I can't figure out why
Inside your function, z
and spins
refer to the same list, which is also known by the global name of spin
. If you modify one, those changes are visible through the other names as well. The variable z
is superfluous.
If you want z
to be a copy of spins
then just do:
z = spins[:]
or:
z = list(spins)