Recursive tuples

Posted by on September 26, 2008

Now,
I have been thinking about this for a few days now… Is it possible to create a tuple in python that refers to itself. I don’t mean via some other object, so the following does not count:

def recursive():
    l = []
    t = (l,)
    l.append(t)
    return t

I believe it is possible to do directly from C, but I can not think of a way to do it from within python.

The idea of creating a recursive tuple was spawned from this little comment I found in the pickle source code: “… recursive tuples are a rare thing”. At first I thought it was talking about a tuple that directly refers to itself, but then figured that it must be talking about tuple’s that indirectly refer to themselves.

Comments

Respond | Trackback

Comments

Comments: