+ 5

Python arrays - Quite complicated an assignment....

It seems to me this code: arr = [4,3,1,2] arr[0], arr[arr[0]-1] = arr[arr[0]-1], arr[0] print(arr) functions as per these steps: 1) arr[arr[0]-1] = arr[3] = 2 and arr[0] = 4 are stored "on the right" 2) arr[arr[0]-1] = arr[3] = 2 is assigned to arr[0] 3) now, arr[0] is changed to 2, so arr[arr[0]-1] = arr[1], and arr[1] is assigned value "4" previously stored "on the right". Is it so?

18th Sep 2019, 12:16 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 Respuestas
+ 6
Nikita, please stop spamming in the Q&A. if you keep it up you will be deactivated.
19th Sep 2019, 5:15 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
https://docs.python.org/3/reference/simple_stmts.html Quoting 7.2. Assignment statements "An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right." So yeah, your description of the process is correct.
19th Sep 2019, 3:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
LONGTIE👔 lol. To late, whatever she did. You're right. She's blocked
19th Sep 2019, 7:19 PM
Kidale Smith
Kidale Smith - avatar