'temporary variable doesn't store the original value
I have this list of lists:
lst = [[1],[2],[3],[4]]
And I want to move the i+1 element to the [0] index, like this:
[[2],[1],[3],[4]] / [[3],[1],[2],[4]] / [[4],[1],[2],[3]]
This is my code:
lst = [[1],[2],[3],[4]]
a = []
count =0
for i in range(1,5) :
temporary = lst
lst.insert(0,lst[i])
del lst[i+1]
a.append(lst)
print(lst,temporary)
break
I see that the temporary variable doesn't store the initial values of lst. I assign the values of lst variable to temp variable before I make changes on the lst, hence I expect the temp variable to hold the initial values of lst, and not the changed values of lst. Where is my mistake?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
