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: 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 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> 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 23/02/2014 17:48, Roy Smith wrote: > In article , > Grant Edwards 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