Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.081 X-Spam-Evidence: '*H*': 0.84; '*S*': 0.00; 'nested': 0.07; 'class:': 0.16; 'tab': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'case.': 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; '[1]': 0.29; 'am,': 0.29; '[2]': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'example,': 0.37; 'wrong': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; '12,': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'more': 0.64; 'mar': 0.68; 'pardon': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=XHKiKcet7tpw3hM1OLM/a7grA4Y9UqMIETeHhHDivO4=; b=CPznS6hhNZi1th9rCGlK0O+PFd3EionOFMKAxr6OxlvzeN9EfMG2l6jrWb0Qw3Hgmc VLkkotTTr90FmbS0+ZK2/lAhb7Gku3HLt8NDR602BLDiVpuRpjVArj1ZzfqnM/7cg7Kh xK+uxC67dLxdOogy0fYK85+n+ONlepZK5w0INnT+YiMntz88/jbP78T87NzZJ4llHbm/ P5mlQFam1XdD7AWNkRMTZfrzwdIHRaBL2EQRvyZ73FWDZ4l29hziSZ3N8dfiUWZ6mNfz OY9kRUeCObYN6t6EX/kpbsksk2j/TkzhoLpZ0BW7sKiqSXKU4SHQ0dQavFThdd0TApWB iDGg== X-Received: by 10.68.170.66 with SMTP id ak2mr3794746pbc.5.1394617952451; Wed, 12 Mar 2014 02:52:32 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53202B57.7060504@rece.vub.ac.be> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> <53202B57.7060504@rece.vub.ac.be> From: Ian Kelly Date: Wed, 12 Mar 2014 03:51:52 -0600 Subject: Re: Tuples and immutability To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394617961 news.xs4all.nl 2884 [2001:888:2000:d::a6]:44544 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68266 On Wed, Mar 12, 2014 at 3:39 AM, Antoon Pardon wrote: > The documentation is wrong at that point as the following code illustrates. Either way it still has to do a getitem and a setitem, but if you have a more nested structure then the extra getitems are not repeated. For example, using your logdict class: >>> tab = logdict() >>> tab[1] = logdict() [1] <= <__main__.logdict object at 0x02A2E430> >>> tab[1][2] = logdict() [1] => <__main__.logdict object at 0x02A2E430> [2] <= <__main__.logdict object at 0x02A2EB10> >>> tab[1][2][3] = ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value'] >>> tab[1][2][3] += [' with extra tail'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] => ['value'] [3] <= ['value', ' with extra tail'] versus: >>> tab[1][2][3] = ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value'] >>> tab[1][2][3] = tab[1][2][3] + [' with extra tail'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] => ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value', ' with extra tail'] As you can see the += version does two fewer getitem calls in this case.