Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 [...]?

like image 854
Jim Simons Avatar asked Nov 16 '10 16:11

Jim Simons


People also ask

What is a circular reference in Python?

When two objects in Python holds reference of each other, it is known as circular reference. Circular reference could cause memory leak in Python versions below 3.4. We as good programmers, should use weak references to create circular reference to prevent potential leak of memory. I am an engineer by education and writer by passion.

What is circular linked list in Python?

Circular Linked Lists are data structures that are used to store lists. It is very similar to linked lists but with a few extra features. In this tutorial, we will discuss what a circular linked list is, we will implement it in python and see its output. We must first define linked lists before moving on to circular linked lists.

How do you iterate through a circular linked list?

There’s a head that points to the start of the list which is used to enter the list and iterate through the circular linked list. To create a circular linked list, we create two classes: the first one for nodes and the second one for the linked list that will use the nodes.

What are the attributes of a circular linked list?

In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the rear are adjacent to each other.


2 Answers

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.

like image 64
DNS Avatar answered Oct 07 '22 11:10

DNS


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.

like image 42
Ignacio Vazquez-Abrams Avatar answered Oct 07 '22 11:10

Ignacio Vazquez-Abrams