I have these lines of codes in a class in python:
1 for i in range(len(self.rg_nodes_range)):
2 tmp_rg = self.rg_nodes_range
3 tmp_rg.pop(i)
The value for self.rg_nodes_range is:
self.rg_nodes_range = [20, 21]
I expect that at the start of every loop, tmp_rg gets the value of [20, 21], and then in line 3, drop the corresponding index (i) from tmp_rg. For example, I want tmp_rg to be [21] at the end of the first iteration (when i==0), and to be [20] at the end of the second iteration (when i==1).
But it seems that it's not happening. I put some breakpoints and found out that in the first iteration, in line 3, tmp_rg and self.rg_nodes_range both change from [20, 21] to [21]. I double-checked it with these lines of code:
p = [1, 2, 3]
tp = p
tp.pop(0)
print(p)
print(tp)
and the output was (both p and tp changed):
[2, 3]
[2, 3]
Do you know what happens here? And how can I fix it to obtain my expected outputs? Thank you.