13

I just got some weird output of a python script:

[[(7, 6), (6, 4), (7, 2)], [...], [...], [...], [(7, 6), (8, 4), (7, 2)], [...], [...], [...], [...], [...], [...], [...]]

The output should be a list of lists of tuples. But I have no idea why [...] appears.

What does [...] mean?

I don't think its an empty list, as an empty list were []. Are these perhaps duplicates?

Harley Holcombe
  • 175,848
  • 15
  • 70
  • 63
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • This might help - http://stackoverflow.com/questions/118370/how-do-you-use-the-ellipsis-slicing-syntax-in-python – arunkumar Aug 28 '11 at 19:10
  • @arunkumar: The `repr` of `Ellipsis` is `"Ellipsis"`. – Rosh Oxymoron Aug 28 '11 at 19:59
  • 3
    See also: [What is \[…\] in Python 2.7?](http://stackoverflow.com/q/17160162/562769) – Martin Thoma Jun 18 '13 at 20:10
  • 3
    Please note that I have asked this question two years before the question came up that I've linked to. So the duplicate is rather the new question than my question. – Martin Thoma Jun 20 '13 at 18:52
  • 1
    not a duplicate, this question is way older than http://stackoverflow.com/q/17160162/2932052 – Wolf Feb 17 '17 at 12:05
  • Duplicates are not [necessarily the newest one](http://meta.stackexchange.com/q/10841/148169). The goal is to keep the best answers and [this is a *far* better answer](http://stackoverflow.com/a/17163521/344286) than any answer here. – Wayne Werner Feb 17 '17 at 13:42

1 Answers1

27

It is a recursive reference. Your list contains itself, or at least there is some kind of cycle.

Example:

x = []
x.insert(0, x)
# now the repr(x) is '[[...]]'.

The built-in repr for lists detects this situation and does not attempt to recurse on the sub-list (as it normally would), because that would lead to infinite recursion.

Note that ... doesn't necessarily tell you which list is referred to:

y, z = [], []
x = [y, z]
y.insert(0, z)
z.insert(0, y)
# looks the same as it would if y contained y and z contained z.

so repr is not really a complete serialization format for lists.

As to why you're getting them: we're not psychic, and can't fix the problem with your code unless we see the code.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153