Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'removes': 0.05; '*not*': 0.07; 'function,': 0.07; 'list?': 0.07; 'nested': 0.07; 'operand': 0.07; 'patterns.': 0.07; 'rejected': 0.07; 'python': 0.09; 'commonly': 0.09; 'confuse': 0.09; 'imply': 0.09; 'mutable': 0.09; 'semantics': 0.09; 'typeerror:': 0.09; 'passing': 0.15; 'weird': 0.15; "'int'": 0.16; 'appends': 0.16; 'copied,': 0.16; 'copied.': 0.16; 'does;': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'losing': 0.16; 'merely': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'objection': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'uncommon': 0.16; 'unsupported': 0.16; 'developers,': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'duplicate': 0.17; 'passes': 0.17; 'typing': 0.17; 'obviously': 0.18; '>>>': 0.18; 'proposed': 0.20; 'trying': 0.21; 'do.': 0.21; '"",': 0.22; 'either.': 0.22; 'subject:skip:i 10': 0.22; 'example': 0.23; 'elements': 0.23; "python's": 0.23; 'sets': 0.23; 'idea': 0.24; 'url:bugs': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'andrew': 0.27; 'subject:list': 0.28; 'arrays': 0.29; 'consistency': 0.29; 'received:192.168.1.3': 0.29; 'no,': 0.29; 'objects': 0.29; 'this.': 0.29; 'function': 0.30; 'compatible': 0.30; 'expect': 0.31; 'lists': 0.31; 'url:python': 0.32; 'file': 0.32; 'not.': 0.32; 'received:84': 0.32; "aren't": 0.33; 'cases,': 0.33; 'traceback': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'languages': 0.33; "can't": 0.34; 'list': 0.35; 'lists.': 0.35; 'nov': 0.35; 'expected': 0.35; 'pm,': 0.35; "won't": 0.35; 'something': 0.35; 'list.': 0.35; 'but': 0.36; 'url:org': 0.36; 'characters': 0.36; 'useful': 0.36; 'does': 0.37; 'two': 0.37; 'uses': 0.37; 'being': 0.37; 'why': 0.37; 'passed': 0.37; 'subject:: ': 0.38; 'copying': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'think': 0.40; 'link': 0.60; "you've": 0.61; 'more.': 0.62; 'time,': 0.62; 'behavior': 0.64; 'total': 0.65; 'stuck': 0.65; 'potentially': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'saving': 0.72; 'delegation': 0.84; 'hardly': 0.84; 'multiply': 0.84; 'reply- to:addr:python.org': 0.84; 'type(s)': 0.84; 'reasoning': 0.91; 'besides,': 0.93; 'favour': 0.93; 'mistakes': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=Bd1aI8R2 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=1EKJ2blYo8kA:10 a=RHlel35PpJcA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=4905VYxiF58A:10 a=5si1IOfVAAAA:8 a=uPZiAMpXAAAA:8 a=B2bSIM20ZUjFI9eD_GgA:9 a=wPNLvfGTeEIA:10 a=90B7yJRffNkA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 07 Nov 2012 00:23:44 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Multi-dimensional list initialization References: <50978323$0$6908$e4fe514c@news2.news.xs4all.nl> <5098d2ac$0$29980$c3e8da3$5496439d@news.astraweb.com> <50999214.50100@r3dsolutions.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352248012 news.xs4all.nl 6904 [2001:888:2000:d::a6]:60293 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32857 On 2012-11-06 23:52, Ian Kelly wrote: > On Tue, Nov 6, 2012 at 3:41 PM, Andrew Robinson > wrote: >>> Q: What about other mutable objects like sets or dicts? >>> A: No, the elements are never copied. >> >> They aren't list multiplication compatible in any event! It's a total >> nonsense objection. >> >> If these are inconsistent in my idea -- OBVIOUSLY -- they are inconsistent >> in Python's present implementation. You can't even reference duplicate them >> NOW. >> >>>>> { 1:'a', 2:'b', 3:'c' } * 2 >> >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: unsupported operand type(s) for *: 'dict' and 'int' > > The objection is not nonsense; you've merely misconstrued it. If > [[1,2,3]] * 4 is expected to create a mutable matrix of 1s, 2s, and > 3s, then one would expect [[{}]] * 4 to create a mutable matrix of > dicts. If the dicts are not copied, then this fails for the same > reason > >>> Q: How about if I use delegation to proxy a list? >>> A: Oh no, they definitely won't be copied. >> >> Give an example usage of why someone would want to do this. Then we can >> discuss it. > > Seriously? Read a book on design patterns. You might start at SO: > > http://stackoverflow.com/questions/832536/when-to-use-delegation-instead-of-inheritance > >>> Losing consistency in favour of saving a few characters for something as >>> uncommon as list multiplication is a poor tradeoff. That's why this >>> proposal has been rejected again and again and again every time it has >>> been suggested. >> >> Please link to the objection being proposed to the developers, and their >> reasoning for rejecting it. >> I think you are exaggerating. > >>From Google: > > http://bugs.python.org/issue1408 > http://bugs.python.org/issue12597 > http://bugs.python.org/issue9108 > http://bugs.python.org/issue7823 > > Note that in two out of these four cases, the reporter was trying to > multiply lists of dicts, not just lists of lists. > >> Besides, 2D arrays are *not* rare and people *have* to copy internals of >> them very often. >> The copy speed will be the same or *faster*, and the typing less -- and the >> psychological mistakes *less*, the elegance more. > > List multiplication is not potentially useful for copying 2D lists, > only for initializing them. For copying an existing nested list, > you're still stuck with either copy.deepcopy() or a list > comprehension. > >> It's hardly going to confuse anyone to say that lists are copied with list >> multiplication, but the elements are not. >> >> Every time someone passes a list to a function, they *know* that the list is >> passed by value -- and the elements are passed by reference. People in >> Python are USED to lists being "the" way to weird behavior that other >> languages don't do. > > Incorrect. Python uses what is commonly known as call-by-object, not > call-by-value or call-by-reference. Passing the list by value would > imply that the list is copied, and that appends or removes to the list > inside the function would not affect the original list. This is not > what Python does; the list inside the function and the list passed in > are the same list. At the same time, the function does not have > access to the original reference to the list and cannot reassign it by > reassigning its own reference, so it is not call-by-reference > semantics either. > I prefer the term "reference semantics".