Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17426 > unrolled thread

Re: root[:]=[root,root]

Started byTerry Reedy <tjreedy@udel.edu>
First post2011-12-17 22:08 -0500
Last post2011-12-17 22:08 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: root[:]=[root,root] Terry Reedy <tjreedy@udel.edu> - 2011-12-17 22:08 -0500

#17426 — Re: root[:]=[root,root]

FromTerry Reedy <tjreedy@udel.edu>
Date2011-12-17 22:08 -0500
SubjectRe: root[:]=[root,root]
Message-ID<mailman.3776.1324177728.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web