root[:]=[root,root]

Lie Ryan lie.1296 at gmail.com
Fri Dec 16 23:24:50 EST 2011


On 12/17/2011 01:40 PM, YAN HUA wrote:
> Hi,all. Could anybody tell how this code works?
>  >>> root = [None, None]

First, you're creating a list of two None, let's say it's list-1. Then 
you bind the name 'root' to list-1.

>  >>> root[:] = [root, root]

Next, you assign list-1's first member with list-1 and list-1's second 
member with list-1.

>  >>> root
> [[...], [...]]

The result is a recursive list, both list-1's first and second  member 
is list-1 itself.

>  >>> root[0]
> [[...], [...]]
>  >>> root[0][0][1][1][0][0][0][1][1]
> [[...], [...]]
>  >>>
>
> Thanks.
>
>





More information about the Python-list mailing list