I have a question about python swap like a, b = b, a
.
Actually, the following is the solution code of EPI Python 5.10: apply_permutation.py
def apply_permutation(perm: List[int], A: List[int]) -> None:
for i in range(len(A)):
while perm[i] != i:
A[perm[i]], A[i] = A[i], A[perm[i]]
perm[perm[i]], perm[i] = perm[i], perm[perm[i]]
But, at the first time, I wrote the last line like this, (the order is different)
perm[i], perm[perm[i]] = perm[perm[i]], perm[i]
then, the result was different !
Can anyone tell me why ?
I tried to find solution in internet but, I even don’t know the key word for this issue.
Thank you.