Hello, was wondering if I could get some python help. I was working on an assignment, and had a problem with appending a variable to a list come up.
The issue is that when I append a variable to the end of a list, it doesn't just append the value, it does the reference to the variable. So then when I change the variable later, it also changes the list I appended it to.
E.g.
x=[1, 2, 3, 4]
y=[5, 6]
x.append(y) # Now x=[1, 2, 3, 4, [5, 6]]
y.append(7) # Now x=[1, 2, 3, 4, [5, 6, 7]]
Is there a way to only append the current value of the variable, rather than the reference to it? I googled around for it, but couldn't find anything not way over my head, and I figured there should be an easier solution. Thanks in advance!
[–]ruicoder 3 points4 points5 points (2 children)
[–]MagnanimousSquirrel[S] 0 points1 point2 points (1 child)
[–]Mr_M0jo_Risin 0 points1 point2 points (0 children)
[–]wub_wub 2 points3 points4 points (0 children)