Jim Simons
Jim Simons

Reputation: 53

Circular Reference with python lists

Can someone explain this?

>>> x = x[0] = [0]
>>> x
[[...]]
>>> x is x[0]
True
>>> x[0][0][0][0][0][0][0]
[[...]]
>>> x in x
True

what is [...]?

Upvotes: 5

Views: 2542

Answers (3)

nmichaels
nmichaels

Reputation: 50951

iPython will do this:

[<Recursion on list with id=38505216>]

It's the same thing; the interpreter telling you that you have a recursive data structure.

Upvotes: 4

DNS
DNS

Reputation: 38189

That's just Python telling you that you have a circular reference; it's smart enough not to enter an infinite loop trying to print it out.

Upvotes: 15

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

It's output by the method responsible for generating the representation of the structure. It represents a recursive structure, elided since it can be nested infinitely.

Upvotes: 3

Related Questions