Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'interpreter': 0.05; 'list...': 0.07; '*args,': 0.09; 'arguments': 0.09; 'function,': 0.09; 'immutable': 0.09; 'python': 0.11; 'def': 0.12; '(1,': 0.16; '(2,': 0.16; 'accepts': 0.16; 'mutable': 0.16; 'reason).': 0.16; 'tuple.': 0.16; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'example': 0.22; 'error': 0.23; 'either.': 0.24; '(or': 0.24; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'restrict': 0.30; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'overhead': 0.31; 'tuples': 0.31; 'lists': 0.32; 'quite': 0.32; 'fri,': 0.33; 'core': 0.34; 'agree': 0.35; 'common': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'returning': 0.36; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'within': 0.65; 'believe': 0.68; 'lose': 0.68; 'containing': 0.69; '9:45': 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:content-transfer-encoding; bh=yGU64tdDkRez8il2ucM40FwtcA2qNpV5WfE5wN/mYLc=; b=fni6deglObKiGoSLLupWWocy+xqPezoj6XfQVnawGb3B1uvxXANsDUMIPgJ5kkWOiS pbF8LVzwYfEn0P3OM0KCh2g1oj6mNmpR4SZ5E9tq+aFhivH0yAOtzd7irebpT4RyUSRh SW57k19eLojOhU6mTbdwGSl1FlvgxKHWGrcPV/KiVbLgWWwD/EjRMvXcaJZ0js9Xjhaj 5eZvE4dqytNbH1mQyo9ET+F/sAa46DtOohPjMuWOMTp4rVxZAiL/0F1h2TUnHJo4l9Wj QAVYUuw8KVNsVF3UGqCEjRm6zHAKI4ydiF7t2GbK8O+xcu1LVqs+nW71bbLtZO66jc+p n3Hg== X-Received: by 10.68.103.97 with SMTP id fv1mr8013760pbb.64.1393652137168; Fri, 28 Feb 2014 21:35:37 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> From: Ian Kelly Date: Fri, 28 Feb 2014 22:34:56 -0700 Subject: Re: Tuples and immutability To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393652140 news.xs4all.nl 2914 [2001:888:2000:d::a6]:53683 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67294 On Fri, Feb 28, 2014 at 9:45 PM, Mark H. Harris wro= te: > I really believe IMHO that the error should have come when you made the l= ist an item of a tuple. An immutable object should have NO REASON to conta= in a mutable object like list... I mean the whole point is to eliminate th= e overhead of a list ... why would the python interpreter allow you to plac= e a mutable object within an immutable list in the first place. This is j= ust philosophical, and yes, the core dev's are not going to agree with me o= n this either. One very common example of tuples containing lists is when lists are passed to any function that accepts *args, because the extra arguments are passed in a tuple. A similarly common example is when returning multiple objects from a function, and one of them happens to be a list, because again they are returned in a tuple. def f(*args): print(args) return (args[1:]) >>> result =3D f(1, 2, 3, [4, 5]) (1, 2, 3, [4, 5]) >>> print(result) (2, 3, [4, 5]) Both of these things are quite handy, and if you restrict tuples from containing lists, then you lose both of them (or you switch to lists and lose the optimization for no good reason).