I was trying to solve a problem and I encountered this situation:
A = ['2', '3', '4', '1']
B = []
for item in A:
B += [item]
for i in range(len(A)):
B[int(A[i]) - 1] = str(i + 1)
print(int(A[i]) - 1)
The output reads
1
2
3
0
This is fine. However, in my first attempt, I actually did
A = ['2', '3', '4', '1']
B = A
for i in range(len(A)):
B[int(A[i]) - 1] = str(i + 1)
print(int(A[i]) - 1)
But this time the output reads
1
0
3
2
I don't see the reason the two outputs being different. I thought in both codes B are similarly defined- which is equal to A at first.