+ 3
operations that do or don't change Python list object ids?
So I still marvel at the subtleties of Python list object references. For an example (based on a challenge quiz question I just saw) see attached code. Some operations leave a list id unchanged, while others that essentially do the same thing (but in a different way under the hood, apparently) create a new object reference. Can anyone provide a rational explanation for the different behavior? (Bonus points for explaining why the difference might be useful!) https://code.sololearn.com/cLlcWMLPtbr0/?ref=app
2 Answers
+ 3
I have marveled the same. I found this answer helpful on stackoverflow: https://stackoverflow.com/questions/2347265/why-does-behave-unexpectedly-on-lists
+ 1
Just now saw your reply, Mark, thanks. Very thorough and helpful discussion at that stack overflow link.