Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'behave': 0.07; 'python': 0.08; 'append': 0.09; 'underlying': 0.09; 'am,': 0.12; 'docs,': 0.16; 'cc:addr:python-list': 0.16; 'subject:question': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'cheers,': 0.20; 'java': 0.21; 'cc:no real name:2**0': 0.21; "aren't": 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'knowing': 0.23; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'sfxlen:0': 0.23; 'cc:2**0': 0.26; 'mainly': 0.28; 'lists': 0.28; "i'm": 0.28; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'array': 0.30; 'yes.': 0.30; 'chris': 0.30; 'received:209.85.212': 0.33; "can't": 0.33; 'calling': 0.34; 'subject:lists': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'linked': 0.38; 'received:209': 0.39; 'more': 0.61; 'below': 0.62; 'guarantee': 0.66; '10:20': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=3ilyuKJYoczTrFSjrr7Ok6FFbAdAaaxOfVRegk9Cbis=; b=LkbXtZGt3o0IrcYBdceHD3awa6kucrnJp1Dku71Zbr4SXWF2aZD2U5vJWZZCPcQgRW SgM+YItpNXQjPCBc+BACcvILgMsjzuUPU4LondYQ/FQLRX1Z71ltF9FMqqBCLv/04zo6 NILenJrX5I+ihVJsb4g4W2qGEblxC4tSBQpFg= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Wed, 15 Feb 2012 10:35:25 -0800 X-Google-Sender-Auth: VffW2TMJVN_Sn-tzjufErR2DB9I Subject: Re: Complexity question on Python 3 lists From: Chris Rebert To: Franck Ditter Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQmizMU6pYOcWnth5hLLbfD1rgV+87Rk4uP0bmz+tqAs5QosoN/YP7VIMJ1MVwiLEnjT15A0 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329330928 news.xs4all.nl 6912 [2001:888:2000:d::a6]:33307 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20457 On Wed, Feb 15, 2012 at 10:20 AM, Franck Ditter wrote: > What is the cost of calling primes(n) below ? I'm mainly interested in > knowing if the call to append is O(1), even amortized. > Do lists in Python 3 behave like ArrayList in Java (if the capacity > is full, then the array grows by more than 1 element) ? Yes. Python lists aren't linked lists. list.append() resizes the underlying array intelligently to give O(1) performance, although I can't find any guarantee of this in the docs, but it is true in practice for all major Python implementations. Cheers, Chris