Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'python.': 0.02; 'interpreter': 0.05; 'contexts': 0.09; 'objects,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; '3],': 0.16; 'immutable,': 0.16; 'mutability': 0.16; 'mutable': 0.16; 'objects.': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'feb': 0.22; '>>>': 0.22; 'programming': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'appreciated.': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'comments': 0.31; 'agreed.': 0.31; 'consisting': 0.31; 'gary': 0.31; 'ok.': 0.31; 'tuples': 0.31; 'another': 0.32; 'linux': 0.33; 'url:python': 0.33; 'totally': 0.33; 'could': 0.34; 'common': 0.35; 'definition': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'two': 0.37; 'easily': 0.37; 'problems': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'break': 0.61; 'no.': 0.61; 'john': 0.61; "you'll": 0.62; 'kind': 0.63; 'such': 0.63; 'choose': 0.64; 'more': 0.64; 'useful.': 0.68; 'legal': 0.71; '2014,': 0.84; 'fragment': 0.84; 'subject:good': 0.84; 'problems?': 0.91 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 :cc:content-type; bh=qHRGXnlcysYtqEGBCEXfC1w3gFTtQKciZWtZH9w7BxA=; b=d9sv1csovPX0uyRIeEej8HNCTYnTxUxi0RRkKbvswuevXErtlu6kGNLvZLFk6PCeEx KndugoHYg2qYHA81aZdzkouO0xcDyO/7O+BCnAqYpcA+/x3YMKTB83LSxMOv1sQVq6th +381EL2vOMdNqHkNzTh2hs7uCQjHFLh8VaBkfR09zC+WAMk4puN81JuowaBnjeOhtTeD A/bEgI07l9bzTxfhNf5gd7E4DWd51WkzsM/LHCjaTx/VMWF01opNQf6MT+sS1/Z8yAS/ OscaUgWBrbesZB6KCiXToE7VSu6opEXNeyCO7gBoAi6uoTAGwjpoMv9dP/bboAEyweum gblA== X-Received: by 10.140.23.148 with SMTP id 20mr647700qgp.89.1396770998920; Sun, 06 Apr 2014 00:56:38 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53410185.6050304@islandtraining.com> References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> From: Devin Jeanpierre Date: Sun, 6 Apr 2014 00:55:58 -0700 Subject: Re: Mutable objects inside tuples - good or bad? To: Gary Herron Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396771007 news.xs4all.nl 2926 [2001:888:2000:d::a6]:52429 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69749 On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron wrote: > On 04/05/2014 11:53 PM, John Ladasky wrote: >> >> I find this programming pattern to be useful... but can it cause problems? > > No. > > What kind of problems are you considering? It won't break Python. It's > perfectly legal code. Agreed. Putting mutable objects inside tuples is common and totally OK. > The tuple c is still immutable, consisting of two specific objects, and (as > always) without regard to the specifics or contents of those two objects. You can choose to define mutability that way, but in many contexts you'll find that definition not very useful. c is such that you could have another variable d, where the following interpreter session fragment is easily possible: >>> c == d True >>> foo(c) >>> c == d False -- Devin >> Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >> [GCC 4.8.1] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> a = [1,2,3] >>>>> b = [4,5,6] >>>>> c = (a,b) >>>>> c >> >> ([1, 2, 3], [4, 5, 6]) >>>>> >>>>> c[0][0] = 0 >>>>> c >> >> ([0, 2, 3], [4, 5, 6]) >> >> Comments appreciated. > > > -- > https://mail.python.org/mailman/listinfo/python-list