+ 3
Donât understand the logic
UPD: Solved, great thanks for responses. Hello. Here is the code: x=[4,3,1,2] x[0],x[x[0]-1]=x[x[0]-1],x[0] print(x) Output is [2, 4, 1, 2] I donât understand why it is not [2, 3, 1, 4]. Because it seems to me that second line means x[0] (first member in a list, i.e 4) and x[x[0]-1] ( i think it is x[4-1] i.e. x[3] i.e 2) should switch places. Please help
2 Answers
+ 4
This is called parallel reassignment âșïž
For ease of understanding, you should be aware that the right side of the expression remains unchanged, while the left side of the expression is interactive (that is, it changes instantly):
x[0] = x[4-1] = 2 and x[2-1] = 4 đ