Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'immutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'semantic': 0.09; 'python': 0.11; '(just': 0.16; 'complained': 0.16; 'expression,': 0.16; 'finney': 0.16; 'rather,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'semantics': 0.16; 'tuple.': 0.16; 'dependent': 0.19; 'code,': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'helpful': 0.24; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; 'strongly': 0.30; 'went': 0.31; 'operations.': 0.31; 'tuples': 0.31; 'wright': 0.31; 'writes:': 0.31; 'lists': 0.32; 'subject:all': 0.32; 'up.': 0.33; 'url:python': 0.33; 'subject:time': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; "can't": 0.35; 'common': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:com.au': 0.36; 'representing': 0.36; 'sequence': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list.': 0.37; 'represent': 0.38; 'ben': 0.38; 'lists.': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'subject:Can': 0.60; 'url:3': 0.61; 'matter': 0.61; 'our': 0.64; 'different': 0.65; 'skip:\xe2 10': 0.65; 'sam': 0.68; '8bit%:21': 0.69; 'received:125': 0.84; 'cause,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Can tuples be replaced with lists all the time? Date: Sun, 23 Feb 2014 15:49:19 +1100 References: <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: vmx15867.hosting24.com.au X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:CgSOCePpVvzDz6vqHQrl8zA3CZI= 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393130974 news.xs4all.nl 2893 [2001:888:2000:d::a6]:35195 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66917 Sam writes: > My understanding of Python tuples is that they are like immutable > lists. That's a common expression, but I think it's not a helpful way to think of them. Rather, the different sequence types have different semantic purposes: * For representing a sequence where each item means exactly the same no matter which position it's in (a “homogeneous sequence”), use a list. * For representing a sequence where the meaning of each item is strongly dependent on its position in the sequence (a “heterogeneous sequence”), use a tuple. See for the official Python description of the type differences. > If this is the cause, why can't we replace tuples with lists all the > time (just don't reassign the lists)? Correct me if I am wrong. Because we need to represent different semantic concepts in our code, and have each type support the semantics with different operations. -- \ “I went camping and borrowed a circus tent by mistake. I didn't | `\ notice until I got it set up. People complained because they | _o__) couldn't see the lake.” —Steven Wright | Ben Finney