Raymond Hettinger added the comment:

This is the expected behavior.
The assignments are made left-to-right.
The first use of L2[1] is updated BEFORE the second use as index.

The assignments are equivalent to:
==================================
>>> L1 = [1,3,2,4]
>>> L2 = [1,3,2,4]
>>> tup = L2[L2[1] - 1], L2[1]
>>> tup
(2, 3)
>>> L2[1] = tup[0]
>>> L2[L2[1] - 1] = tup[1]
>>> L2
[1, 3, 2, 4]

Which is the same as you observed
=================================
>>> L1 = [1,3,2,4]
>>> L2 = [1,3,2,4]
>>> L2[1], L2[L2[1] - 1] = L2[L2[1] - 1], L2[1]
>>> L2
[1, 3, 2, 4]

The core issue is that L2[1] is being used twice during the series of 
assignments.  First it gets updated with L2[1] = 3.  Then L2[1] is used again 
AFTER it has been updated.

----------
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30729>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to