开发者

What does [...] (an ellipsis) in a list mean in Python? [duplicate]

This question already has answers here: 开发者_如何学编程 What do ellipsis [...] mean in a list? (5 answers) Closed 9 years ago.

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜