Explanation of list reference

Chris Angelico rosuav at gmail.com
Sat Feb 15 08:05:00 CET 2014

On Sat, Feb 15, 2014 at 5:44 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> You just need to recognise that
> objects can contain themselves:
> py> L = []
> py> L.append(L)
> py> L in L
> True
> Of course, if you are a fan of the Doctor Who television show, you won't
> be concerned by this. If the TARDIS can materialise inside itself, then
> there isn't any problem with lists containing themselves either.

They certainly can. In my MUD, every object has a location (which may
be the equivalent of None); generally, a person's location is a room,
and a grabbable object's location is either a room or a person, but
it's possible for a room to have a location... a Dungeon Master can
create a workroom, which is in his inventory, and then enter that

Incidentally, the destruction of an object simply involves moving it
to nowhere. Since "nowhere" doesn't keep any references to the things
put there, those objects promptly cease to exist. It's just like
Western society - you don't actually destroy anything, you just throw
it away (out of sight, out of mind), and let the garbage collector
dispose of it for you :)


More information about the Python-list mailing list