I happened on this peculiar behaviour accidentally:
>>> a = []
>>> a[:] = ['potato', a]
>>> print a
['potato', [...]]
>>> print list(a)
['potato', ['potato', [...]]]
By what mechanism does calling list(a)
unroll one level of recursion in the string representation of itself?
list()
makes a shallow copy. The outer list is no longer the same object as the list it contains. It is printed as you would expect.The
...
is only displayed when an item contains itself -- that is, the same object.list(a)
makes a copy of the list, so the innera
isn't the same object. It only shows the...
when it gets to "a inside a", not "a insidelist(a)
".