Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'cpython': 0.05; 'skip:` 10': 0.07; 'subject:Question': 0.07; 'append': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'question.': 0.14; 'behavior,': 0.16; 'curious.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:`': 0.16; 'sure.': 0.16; 'memory': 0.22; 'header:X -Complaints-To:1': 0.27; "i'm": 0.30; '(which': 0.31; 'there,': 0.34; 'hi,': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'entire': 0.61; 'first': 0.61; 'more': 0.64; 'promise': 0.68; 'saving': 0.69; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:Question about `list.insert` Date: Thu, 6 Feb 2014 21:54:42 -0500 (EST) Organization: news.gmane.org References: <4041bba7-91bc-4803-9150-2fcf14ecb5a9@googlegroups.com> X-Gmane-NNTP-Posting-Host: dpc6744192175.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391741496 news.xs4all.nl 2837 [2001:888:2000:d::a6]:53105 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65575 cool-RR Wrote in message: > Hi, > > I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just allocate more memory to the left of the list and put the item there, saving a lot of resources? > Excellent question. list does not promise better than O (1) behavior, and CPython in particular will copy, I'm pretty sure. However that's exactly what collections.deque is for. -- DaveA