List of lists surprising behaviour

bart.c bartc at freeuk.com
Fri Jun 18 07:07:38 EDT 2010


Lie Ryan wrote:
> On 06/18/10 20:00, bart.c wrote:
>> (I
>> don't know if Python allows circular references, but that would give
>> problems anyway: how would you even print out such a list?)
>
>
> Python uses ellipsis to indicate recursive list:
>
>>>> a = [1, 2, 3]
>>>> a.append(a)
>>>> a
> [1, 2, 3, [...]]

Ok, perhaps whatever logic print uses to know when to stop and show "...", 
can also be used by copy handlers...

(Although I have an issue with the way that that append works. I tried it in 
another, simpler language (which always does deep copies):

L:=(1,2,3)
L append:= L
print L

output:  (1,2,3,(1,2,3))

which is exactly what I'd expect, and not (1,2,3,(1,2,3,(1,2,3,...))) )

-- 
bartc 




More information about the Python-list mailing list