Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; ';-)': 0.03; '*not*': 0.07; 'subject:Question': 0.07; 'repeated': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'language,': 0.12; '-tkc': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'len(self)': 0.16; 'roy': 0.16; 'subject:`': 0.16; 'unneeded': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'performing': 0.26; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'chase': 0.31; 'operations.': 0.31; 'class': 0.32; 'fri,': 0.33; 'received:google.com': 0.35; 'there': 0.35; 'list': 0.37; 'pm,': 0.38; 'does': 0.39; 'it!': 0.67; 'promise': 0.68; 'smith': 0.68; 'skip:a 40': 0.72; 'behavior': 0.77; 'to:none': 0.92; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qZ65y8TOPDTcnO4oCOPUUsN6DPLx/mK63DJ7drDGpd0=; b=MiSAIVUeSYLbWZ3VZYSJHMF4PoG4IpJ9RzVU3BJ5rmZwTGjxw6pT34C6IHFDreeUwI yCTiUZDXtxqX+/9zeMpsm6xPEZmuBmZuIawwORyDP+VLLNLNnwnu8vRkYzDaD1CyCTOE 1uKbfjwsy2pryBY/vpNFlHf1Uzlt05zXXxTm0MVY8+IjaopiE0LGWQI31v4mGlvNL6ca oPSXWyP1vLHdf0sXNWkDsF5UHLl0FL9qXlL4C+gEHLqLuNcefbqNh5CNhITPX1vGGoGC bOXqVHOi4FQZk53XDlnixIiCe4oKIAk0tSbu3egwNx/qRXYV+WyilT52gJNxeRtHiUcn eP3A== MIME-Version: 1.0 X-Received: by 10.68.108.194 with SMTP id hm2mr16955345pbb.22.1391743243293; Thu, 06 Feb 2014 19:20:43 -0800 (PST) In-Reply-To: <20140206211130.3ec5b0d8@bigbox.christie.dr> References: <4041bba7-91bc-4803-9150-2fcf14ecb5a9@googlegroups.com> <20140206211130.3ec5b0d8@bigbox.christie.dr> Date: Fri, 7 Feb 2014 14:20:43 +1100 Subject: Re: Question about `list.insert` From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391743247 news.xs4all.nl 2937 [2001:888:2000:d::a6]:45067 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65582 On Fri, Feb 7, 2014 at 2:11 PM, Tim Chase wrote: > On 2014-02-06 22:00, Roy Smith wrote: >> > list does not promise better than O(1) behavior >> >> I'm not aware of any list implementations, in any language, that >> promises better than O(1) behavior for any operations. Perhaps >> there is O(j), where you just imagine the operation was performed? > > Pish...there's always O(0) which is achieved by *not* performing some > unneeded operation ;-) > > -tkc Ooh! Ooh! I got it! class fast_list(list): def append(self,obj,randrange=random.randrange): if len(self) and randrange(len(self)): return return super().append(obj) Repeated appends to this list are amortized O(0)! ChrisA