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


Groups > comp.lang.python > #67370

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'cpython': 0.05; 'element': 0.07; '[1,': 0.09; 'lawrence': 0.09; "person's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'assume': 0.14; 'language.': 0.14; '(1,': 0.16; 'containers': 0.16; 'name)': 0.16; 'namedtuples': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'tuple': 0.16; 'language': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'appears': 0.22; 'memory': 0.22; 'tests': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; '---': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'needed.': 0.30; "i'm": 0.30; 'usually': 0.31; 'context,': 0.31; 'etc.).': 0.31; 'struct': 0.31; 'tuples': 0.31; 'lists': 0.32; 'subject:all': 0.32; '(e.g.': 0.33; 'subject:time': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'except': 0.35; 'something': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'add': 0.35; 'subject:?': 0.36; 'similar': 0.36; 'list': 0.37; 'to:addr :python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'subject:Can': 0.60; 'free': 0.61; 'viruses': 0.61; 'name': 0.63; 'protection': 0.63; 'our': 0.64; 'more': 0.64; 'antivirus': 0.68; 'smith': 0.68; 'results': 0.69; 'million': 0.74; 'article': 0.77; 'edwards': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Can tuples be replaced with lists all the time?
Date Sat, 01 Mar 2014 21:20:10 +0000
References <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> <led9s7$req$1@reader1.panix.com> <roy-099864.12485223022014@news.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-146-12-203.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
In-Reply-To <roy-099864.12485223022014@news.panix.com>
X-Antivirus avast! (VPS 140301-0, 01/03/2014), Outbound message
X-Antivirus-Status Clean
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.7536.1393708830.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393708830 news.xs4all.nl 2838 [2001:888:2000:d::a6]:50837
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67370

Show key headers only | View raw


On 23/02/2014 17:48, Roy Smith wrote:
> In article <led9s7$req$1@reader1.panix.com>,
>   Grant Edwards <invalid@invalid.invalid> wrote:
>
>> 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).
>
> And, of course, namedtuples make that much more explicit.
>
> It also appears that tuples are more memory efficient.  I just ran some
> quick tests on my OSX box.  Creating a list of 10 million [1, 2, 3, 4,
> 5] lists gave me a 1445 MB process.   The name number of (1, 2, 3, 4, 5)
> tuples was 748 MB.  I'm sure this is implementation dependent, but it
> seems plausible to assume similar results will be had on other
> implementations.
>

In CPython a list is overallocated so there's usually spare slots 
available if you want to add something to it.  In contrast you know when 
you create the tuple just how big it is so no overallocation is needed.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

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