Discussion about this post

User's avatar
Shantnu's avatar

Nice.

One trap I've hit sevreal times is: I think I copied an object, like a=b. But all Python does is make a & b point to the same object, so modifying b also changes a!

It's very painful to debug when this goes wrong.

The solution, I found, is to always use deepcopy() when you want to create a new object. But this isn't intuitive, and searching online doesnt give you the simple answer (unless you already know what the problem is)

Expand full comment
jmg74's avatar

So well explained! There are many articles like it, but this is the best one I ever read on this topic!

May I translate this article for my French students and publish the translated version on my website (with a link to the original content, of course)?

In any case, thank you

Expand full comment
5 more comments...

No posts