Message296615
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. |
|
Date |
User |
Action |
Args |
2017-06-22 06:17:39 | rhettinger | set | recipients:
+ rhettinger, ronaldoussoren, ned.deily, Ikaros |
2017-06-22 06:17:39 | rhettinger | set | messageid: <1498112259.55.0.404235483383.issue30729@psf.upfronthosting.co.za> |
2017-06-22 06:17:39 | rhettinger | link | issue30729 messages |
2017-06-22 06:17:39 | rhettinger | create | |
|