[Python-Dev] very slow compare of recursive objects

Neal Norwitz neal@metaslash.com
Mon, 20 Jan 2003 10:50:17 -0500


On Mon, Jan 20, 2003 at 10:32:50AM -0500, Tim Peters wrote:
> [Tim]
> >Tuples can't be recursive,
> 
> [Guido]
> > Oh yes they can be:
> >
> >    >>> L = []
> >    >>> t = (L, L)
> >    >>> L.append(L)
> >    >>>
> 
> That's an example of a tuple *containing* a recursive structure; there's
> still no way, starting at t, to get back to t.  I think mutation is required
> for that.  Like
> 
>     L = [None]
>     t = (L, L)
>     L[0] = t
> 
> Then
> 
>     t[0]0] is t
> 
> and that's what I mean by "recursive tuple" (a tuple that can be reached
> from itself).

What about:

        >>> t = ([],)
        >>> t[0].append(t)
        >>> print t
        ([([...],)],)
        >>> print t[0][0] is t
        True

Not sure if that's a tuple containing a recursive structure or a
recursive tuple.

Neal