Edited for clarity:
Why do the list items not swap?
# python 3.5
lst = [0, 1]
lookup = {0: 1, 1: 0}
lst[0], lst[lookup[lst[0]]] = lst[lookup[lst[0]]], lst[0]
# lst is still unchanged; why aren't items 0 and 1 not swapped
Edited for clarity:
Why do the list items not swap?
# python 3.5
lst = [0, 1]
lookup = {0: 1, 1: 0}
lst[0], lst[lookup[lst[0]]] = lst[lookup[lst[0]]], lst[0]
# lst is still unchanged; why aren't items 0 and 1 not swapped
The rhs is evaluated before the lhs. That's not the problem.
The problem is how the lhs is evaluated. You can prove this to yourself by running this statement:
Note that the assigning to
lst[0]
occurs before the evaluation oflst[lookup[lst[0]]]
. So thelst[0]
in that complex expression is the new value, not the old value.Breaking it down:
So the final result appears unchanged.