My lecturer has set several questions on python, and this one has got me confused, I dont understand what is happening.
x = [[]]
x[0].extend(x)
Python tells me, after running this that x is [[...]], what does the ... mean?
I get even more confused when the result of the following is just [[]]
y = [] # equivalent to x[0]
x = [[]]
y.extend(x)
If y is calculated to be [[]] shouldn't x be calculated to simply being [[[]]]?
What is extend doing? and what does the ... mean?
The ... indicates that the list contains a recursive loop, i.e., at some level something contains itself.  This is because you extended x with x, so you essentially put x inside itself.
There is no ... in the second example because y is a distinct object.  Although it happens to be equal to x[0] in that both are empty lists, they are not the same empty list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With