cyclic data structures

Ewald R. de Wit erdewit at d-e-l-e-t-e.zonnet.nl
Tue Feb 14 05:50:15 EST 2006


John Salerno wrote:
> I'm having some slight trouble understanding exactly why this creates an 
> infinite loop:
>
> L = [1, 2]
> L.append(L)

I tried this with Python 2.3.5 and it handles this tailbiter in a
very pleasantly surprising way:

>>> l = [ 0, 1 ]
>>> l.append( l )
>>> l
[0, 1, [...]]
>>> l[2]
[0, 1, [...]]
>>> l[2][2][2][2][2][2][2][0]
1

The [...] I have never seen before anywhere, is it documented?

--
  --  Ewald

 



More information about the Python-list mailing list