Discussion about this post

User's avatar
Viswa Kumar's avatar

The **ob_item gave away the double pointer play (pointer to the reference) and then as they say, the rest is history 😊. Great writing by the way!

Expand full comment
Edoardo's avatar

For me this is not so much shocking.

Simply lists are stored by reference and if you copy that reference you are still pointing to the same memory area/object.

Maybe because I have a C++ background this doesn’t seem so surprising.

A similar thing happens when you want to have a default empty collection (like a list) in a function argument: if you pass ‘def fun(my_list=[])’, that list is a single one and not created every time you invoke the function (as intended most of the times).

The solution to this problem is to use ‘list()’ instead of ‘[]’

Expand full comment
2 more comments...

No posts