Why does this list swap fail?
Jussi Piitulainen
jussi.piitulainen at helsinki.fi
Mon Nov 14 14:02:33 EST 2016
380162267qq at gmail.com writes:
> L=[2,1]
> L[0],L[L[0]-1]=L[L[0]-1],L[0]
>
> The L doesn't change. Can someone provide me the detail procedure of
> this expression?
The right-hand side evaluates to (1,2), but then the assignments to the
targets on the left-hand side are processed in order from left to right.
This happens:
L[0] = 1
L[L0] - 1] = 2
https://docs.python.org/3/reference/simple_stmts.html#assignment-statements
More information about the Python-list
mailing list