Search code examples
pythonpython-3.xlistjupyter-notebookellipsis

Confusion with Ellipsis in Python


In [81]: a
Out[81]: [[...]]

In [82]: b
Out[82]: [[Ellipsis]]

In [83]: a==b
Out[83]: False

In [84]: ...==Ellipsis
Out[84]: True

Why it is that when Ellipsis are in lists they are not equal, and when they are by themselves they are equal?


Solution

  • Check that

    >>> [[...]] == [[Ellipsis]]
    True
    

    but

    >>> a = []
    >>> a.append(a)
    >>> a
    [<Recursion on list with id=70796424>]
    >>> print(a)
    [[...]]
    >>> a==[[Ellipsis]]
    False
    >>> 
    

    which is expected because you're comparing the Ellipsis object with an ellipsis representation of a recursively defined list.