Python self references
This is a bit of Python trivia but Python containers can store items that are self references.
The way this works is that in Python a list just stores references to Python objects so you can just have a reference to the container. You can create such a list like this:
>>> foo = ['bar', 'baz'] >>> foo.append(foo) >>> foo ['bar', 'baz', [...]] >>> foo is foo True
So you can see here from the object identity test that
foo has a self reference in it now.
This knowledge can be useful sometimes (like explaining to people why there's 2 garbage collection mechanisms in CPython) but for the most part this will just be a bit of trivia.
By Janis Lesinskis
Tags: Python trivia indirection