I created a list called a, when I inserted a at the beginning of the list this happened
>>> a = ['a', 'b', 'c', 'd']
>>> a.insert(0, a)
>>> a
[[...], 'a', 'b', 'c', 'd']
I created a list called a, when I inserted a at the beginning of the list this happened
>>> a = ['a', 'b', 'c', 'd']
>>> a.insert(0, a)
>>> a
[[...], 'a', 'b', 'c', 'd']
Running this code:
a = ['a', 'b', 'c', 'd']
a.insert(0, a)
print(a)
print(a[0])
yields this result:
[[...], 'a', 'b', 'c', 'd']
[[...], 'a', 'b', 'c', 'd']
this leads me to believe this is how python handles printing recursive referencing. a
contains a reference to a
, which contains a reference to a
... meaning there's no good way to actually print it, so it just prints [...]
if you want to include the values of a
inside of a pointer to a
, you might want to copy it
this code:
import copy
a = ['a', 'b', 'c', 'd']
a.insert(0, copy.deepcopy(a))
print(a)
results in this:
[['a', 'b', 'c', 'd'], 'a', 'b', 'c', 'd']