Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of [...] in python? [duplicate]

Instead of a list with some objects in it, I get [...] whenever I run my code. I'd like to know what it means, in order to debug my code.

like image 682
Algunillo Avatar asked Dec 01 '15 09:12

Algunillo


2 Answers

That most probably is a reference to the object itself. Example:

In [1]: l = [0, 1]

In [2]: l.append(l)

In [3]: l
Out[3]: [0, 1, [...]]

In the above, the list l contains a reference to itself. This means, you can endlessly print elements within it (imagine [0, 1, [0, 1, [0, 1, [...]]]] and so on) which is restricted using the ... IMO, you are incorrectly appending values somewhere in your code which is causing this.

A more succinct example:

In [1]: l = []

In [2]: l.append(l)

In [3]: l
Out[3]: [[...]]
like image 94
Anshul Goyal Avatar answered Oct 17 '22 18:10

Anshul Goyal


>>> data = []
>>> data.append([1,3,4])
>>> data
[[1, 3, 4]]
>>> data.append([1,3,data])
>>> data
[[1, 3, 4], [1, 3, [...]]]
>>> data[0]
[1, 3, 4]
>>> data[1]
[1, 3, [[1, 3, 4], [...]]]
>>> data.append([1,2,data])
>>> data
[[1, 3, 4], [1, 3, [...]], [1, 2, [...]]]
>>> data[2]
[1, 2, [[1, 3, 4], [1, 3, [...]], [...]]]

Then it just gets weird

like image 33
Rolf of Saxony Avatar answered Oct 17 '22 17:10

Rolf of Saxony