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


Groups > comp.lang.python > #67391

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'alignment': 0.07; 'memory.': 0.07; '[1,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'references,': 0.09; 'jan': 0.12; 'assume': 0.14; '(1,': 0.16; 'blocks': 0.16; 'boundary,': 0.16; 'length.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'roy': 0.16; 'tuple': 0.16; 'which,': 0.16; 'followed': 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; 'byte': 0.24; 'space.': 0.24; 'header': 0.24; 'references': 0.26; 'right.': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'besides': 0.30; 'needed.': 0.30; "i'm": 0.30; 'usually': 0.31; 'block,': 0.31; 'header,': 0.31; 'tuples': 0.31; 'lists': 0.32; 'subject:all': 0.32; 'subject:time': 0.33; 'subject:the': 0.34; 'subject:with': 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; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'subject:Can': 0.60; 'length': 0.61; 'numbers': 0.61; 'received:173': 0.61; 'first': 0.61; 'name': 0.63; 'more': 0.64; 'smith': 0.68; 'sound': 0.68; 'results': 0.69; 'million': 0.74; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Can tuples be replaced with lists all the time?
Date Sat, 01 Mar 2014 18:15:10 -0500
References <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> <led9s7$req$1@reader1.panix.com> <roy-099864.12485223022014@news.panix.com> <letiu0$hfj$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-254-207.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
In-Reply-To <letiu0$hfj$1@ger.gmane.org>
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.7549.1393715735.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393715735 news.xs4all.nl 2892 [2001:888:2000:d::a6]:42805
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67391

Show key headers only | View raw


On 3/1/2014 4:20 PM, Mark Lawrence wrote:
> On 23/02/2014 17:48, Roy Smith wrote:

>> 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.

The numbers sound right.

> 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.

Besides which, in CPython, a tuple is one block of memory, with a 
PyObject header followed by the object references, while a list uses 2 
blocks of memory. The first has a PyObject header, followed by a 
reference to the list block, its allocated length (minimum 8 I believe), 
and its current in-use length. The over-allocated list block, which must 
also start on a 4 or 8 byte alignment boundary, has the object 
references plus extra space.


-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious 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