Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66917

Re: Can tuples be replaced with lists all the time?

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 <python-python-list@m.gmane.org>
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 <ben+python@benfinney.id.au>
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 <bignose+hates-spam@benfinney.id.au>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7274.1393130974.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


Sam <lightaiyee@gmail.com> 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 <URL:http://docs.python.org/3/library/stdtypes.html> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can tuples be replaced with lists all the time? Sam <lightaiyee@gmail.com> - 2014-02-22 20:06 -0800
  Re: Can tuples be replaced with lists all the time? Paul Rubin <no.email@nospam.invalid> - 2014-02-22 20:28 -0800
  Re: Can tuples be replaced with lists all the time? Chris Angelico <rosuav@gmail.com> - 2014-02-23 15:18 +1100
  Re: Can tuples be replaced with lists all the time? Ben Finney <ben+python@benfinney.id.au> - 2014-02-23 15:49 +1100
  Re: Can tuples be replaced with lists all the time? 88888 Dihedral <dihedral88888@gmail.com> - 2014-02-23 11:45 -0800
  Re: Can tuples be replaced with lists all the time? Roy Smith <roy@panix.com> - 2014-02-22 23:19 -0500
    Re: Can tuples be replaced with lists all the time? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-03-02 17:21 -0500
  Re: Can tuples be replaced with lists all the time? Grant Edwards <invalid@invalid.invalid> - 2014-02-23 17:07 +0000
    Re: Can tuples be replaced with lists all the time? Roy Smith <roy@panix.com> - 2014-02-23 12:48 -0500
      Re: Can tuples be replaced with lists all the time? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 21:20 +0000
      Re: Can tuples be replaced with lists all the time? Terry Reedy <tjreedy@udel.edu> - 2014-03-01 18:15 -0500

csiph-web