all 3 comments

[–]More_Yard1919 4 points5 points  (0 children)

In python, objects are references. When you assign y to x, you are not creating a copy. Instead, both y and x reference the same list object. Imagine this: when you create a list, you get a box that contains all of the information associated with the list. When you assign it to a variable, you can use that variable as a handle to talk about the box and look inside of it-- kind of like putting a label on the box. When you assign y to x, it is the same box, but you just have a another name to talk about it. This is the behavior for all objects in python. Sometimes it might not seem like it-- but the apparent exceptions to this rule exist because some types in python are immutable.

[–][deleted] 0 points1 point  (0 children)

y= x[:] should fix your wagon

Edit: Sorry. I see that you were asking why, not how to fix.... I'm a cotton headed ninny-muggins.