cyclic data structures

Peter Decker pydecker at gmail.com
Mon Feb 13 15:50:45 EST 2006


On 2/13/06, John Salerno <johnjsal at nospamgmail.com> wrote:
> I'm having some slight trouble understanding exactly why this creates an
> infinite loop:
>
> L = [1, 2]
> L.append(L)

'L' is a pointer to a list. You are now adding that pointer to the
very list it points to.

What you're looking for is:

L = [1, 2]
L.append(L[:])

--

# p.d.



More information about the Python-list mailing list