Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed-00.mathworks.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Can tuples be replaced with lists all the time? Date: Sun, 23 Feb 2014 17:07:19 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 24 Message-ID: References: <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> NNTP-Posting-Host: c-24-118-110-103.hsd1.mn.comcast.net X-Trace: reader1.panix.com 1393175239 28122 24.118.110.103 (23 Feb 2014 17:07:19 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 23 Feb 2014 17:07:19 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:67352 On 2014-02-23, Sam wrote: > My understanding of Python tuples is that they are like immutable > lists. 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. In addition to the things related to one being mutable and the other immutable, there is a certain tradition that often results in differnt usages for them. Though it's certainly not required, lists are more often used as variable length _homogeneous_ containers -- sort of like a variable length array or linked list in C. The "type" or "meaning" of element #N is the same as that of element #M. In constrast, tuples are often used as fixed-length heterogenous containers (more like a struct in C except the fields are named 0, 1, 2, 3, etc.). In a particular context, the Nth element of a tuple will always mean one thing (e.g. a person's last name) while the Mth element will always be something else (e.g. a person's age). -- Grant