+ 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

22nd Oct 2017, 9:21 PM
Erik
2 ответов
+ 3
I have marveled the same. I found this answer helpful on stackoverflow: https://stackoverflow.com/questions/2347265/why-does-behave-unexpectedly-on-lists
25th Oct 2017, 1:24 AM
Mark McGhee
Mark McGhee - avatar
+ 1
Just now saw your reply, Mark, thanks. Very thorough and helpful discussion at that stack overflow link.
18th Nov 2017, 5:25 PM
Erik