root[:]=[root,root]
Terry Reedy
tjreedy at udel.edu
Sat Dec 17 22:08:24 EST 2011
On 12/16/2011 9:40 PM, YAN HUA wrote:
> Hi,all. Could anybody tell how this code works?
> >>> root = [None, None]
> >>> root[:] = [root, root]
> >>> root
> [[...], [...]]
> >>> root[0]
> [[...], [...]]
> >>> root[0][0][1][1][0][0][0][1][1]
> [[...], [...]]
A simpler example:
>>> l = []
>>> l.append(l)
>>> l
[[...]]
Python is (now) smart enough to recognize a recursive list and print
'...' instead of going into an infinite loop printing '['s (as it once
did, I believe).
--
Terry Jan Reedy
More information about the Python-list
mailing list