In the Computer Science test, I was asked to determine the output of this code:
L = [12, 3, 1, 5, 13, 18, 85, 10, 2, 74, 1, 12, 3]
i = 1
while i < len(L):
L[i-1], L[i] = L[i], L[i-1]
i += 2
print(L)
The code looks very simple, but there is something that confused me and made my answer wrong and it's the code in line 4.
Let's take an example so that you get how I understood that line of code :
let's take i = 1.
Then L[0], L[1] = L[1], L[0]
This means that L[0] = L[1] (L[0] would be then 3) and L[1] = L[0] (here I thought that this assignment is useless as L[0] is now equal to L[1] = 3)
However, when I came home and executed the code with my laptop, I realized I was wrong but I still don't get my mistake.
Btw, I guess it's maybe the line 4 syntax (2 assignments in only one line)