"Edward C. Jones" <edcjo...@comcast.net> writes: > I am trying to create a collection of hashable objects, where each > object contains references to > other objects in the collection. The references may be circular. > > To simplify, one can define > x= list() > x.append(x) > which satisfies x == [x]. > Can I create a similar object for tuples which satisfies x == (x,)?
You can create a tuple in "C" and then put a reference to itself into it, but I am quite convinced that you cannot do it in Python itself. (Of course, you could use "cython" to generate C code with a source language very similar to Python). But, you do not need tuples; You could use a standard class: >>> class C(object): pass ... >>> c=C() >>> c.c=c >>> d=dict(c=c) >>> d {'c': <__main__.C object at 0xb737f86c>} -- Dieter -- http://mail.python.org/mailman/listinfo/python-list