This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Ikaros, ned.deily, rhettinger, ronaldoussoren
Date 2017-06-22.06:17:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1498112259.55.0.404235483383.issue30729@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-06-22 06:17:39rhettingersetrecipients: + rhettinger, ronaldoussoren, ned.deily, Ikaros
2017-06-22 06:17:39rhettingersetmessageid: <1498112259.55.0.404235483383.issue30729@psf.upfronthosting.co.za>
2017-06-22 06:17:39rhettingerlinkissue30729 messages
2017-06-22 06:17:39rhettingercreate