Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: List semantics [was Re: Slices time complexity] Date: Wed, 20 May 2015 20:54:00 +1200 Lines: 47 Message-ID: References: <9ceklad15llnv3npejq9iuh91soci8aeqo@4ax.com> <7ea01590-a559-46e5-abf5-29622e39aae7@googlegroups.com> <555ac697$0$12910$c3e8da3$5496439d@news.astraweb.com> <862693ca-42cf-4f5b-ac12-133e43e7606b@googlegroups.com> <878uclf3bt.fsf@elektro.pacujo.net> <555af171$0$12995$c3e8da3$5496439d@news.astraweb.com> <874mn9ezaw.fsf@elektro.pacujo.net> <555b2fa9$0$12996$c3e8da3$5496439d@news.astraweb.com> <87oalfooz7.fsf@elektro.pacujo.net> <92992653-d511-4e33-a21d-541eeda4799b@googlegroups.com> <555c225b$0$2769$c3e8da3$76491128@news.astraweb.com> <28bca3fb-653d-40fb-9944-d28b01e77244@googlegroups.com> <555c368c$0$12906$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net yIerhz1A7g7U9k/T9XaGAAn53zRZu3EVNZZ70NyKxAC3KC2Xen Cancel-Lock: sha1:uf3PskMrFRPYwegqzGvur46kLV0= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <555c368c$0$12906$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:90945 Steven D'Aprano wrote: > Code snippet 1: > > x = [[1,2],[1,2]] > > creates a list bound to the name "x", containing a list containing ints 1 > and 2, and a second independent list also containing ints 1 and 2. Using the word "contains" here is misleading, because it conjures a mental picture of physical containment, which is exactly what you *don't* want to suggest. > z = [1,2] > y = [z, z] > > creates a list bound to the name "z", ints 1 and 2; then it creates a second > list, bound to name "y", containing the first list "z" twice. At this point the student thinks, "Um... what? How can an object contain another object *twice*?" If he's still thinking in physical terms, this sentence is nonsensical. It gets even worse with: x = [1, 2] x[1] = x Now you have to say that the list contains *itself* in some weird Tardis-like fashion! I can't think of any way to dispel the confusion verbally without using some word like "reference" or "pointer" or something with an equivalent meaning. Something that suggests a level of indirectness. > A diagram may help, especially for more complicated situations, Seems to me that a diagram is far and away the easiest and most effective way to convey what's really going on. It's difficult to do that with words alone, because English isn't really equipped to talk about it precisely enough. -- Greg