Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17426
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: root[:]=[root,root] |
| Date | 2011-12-17 22:08 -0500 |
| References | <CAPoCtLbKBqU3qkGUmOR7jF3tZogQZUZbOWnAgYBtP3qkAQ5+Bw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3776.1324177728.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: root[:]=[root,root] Terry Reedy <tjreedy@udel.edu> - 2011-12-17 22:08 -0500
csiph-web