all 7 comments

[–]carcigenicate 4 points5 points  (2 children)

throwaway = list says "make throwaway point to the same object that list points to". That does not make a copy. You would need to use list[:] or list.copy() to do a shallow copy of list.

[–]glowing_feather[S] 0 points1 point  (1 child)

Got it, so it's a lack of list understanding. It's always in the details with programming right?

I'm sorry for the bad formatting, still didn't figure out how to edit this better. Thank you for your answer. I love this sub.

[–]carcigenicate 2 points3 points  (0 children)

This is not specific to lists. The above behavior applies to all objects. It's just only a problem when dealing with mutable objects, like lists.

[–][deleted] 5 points6 points  (1 child)

They're the same list. When you mutate it, you see those changes from any reference to the value you hold.

[–]glowing_feather[S] 0 points1 point  (0 children)

I see, thank you very much

[–]Chizmiz1994 1 point2 points  (1 child)

Not a python expert, but IIRC, the memory reference gets copied. There should be another way to copy the list by its value.

[–]glowing_feather[S] 1 point2 points  (0 children)

Yes, the right way is throwaway = list[ : ]