Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'yet.': 0.04; '(even': 0.05; 'handler': 0.05; '(so': 0.07; 'args': 0.07; 'iterate': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'args,': 0.16; 'args.': 0.16; 'element,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gonna': 0.16; 'guilty': 0.16; 'iterable': 0.16; 'iterated': 0.16; 'ought': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'passing': 0.19; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'least': 0.26; 'header:In- Reply-To:1': 0.27; 'rest': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'program,': 0.31; 'usually': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'time:': 0.31; 'subject:time': 0.33; 'copying': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'like,': 0.36; 'doing': 0.36; "i'll": 0.36; 'effort': 0.37; 'list': 0.37; 'list.': 0.37; 'generic': 0.38; 'needed': 0.38; 'whatever': 0.38; 'either': 0.39; 'worry': 0.60; "you're": 0.61; 'first': 0.61; 'times': 0.62; 'myself': 0.63; 'more': 0.64; 'situation': 0.65; 'benefit': 0.68; '20,': 0.68; 'feeling': 0.68; 'million': 0.74; '2015': 0.84; 'tomorrow"': 0.84; 'attitude': 0.91; 'lazy': 0.91; 'to:none': 0.92 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=WgnK1wTtf7KJwB6euJMieKr9M4WTzLS7wOMbsKJXBRc=; b=Mn+Lrfg2Iaji5P6f0y2xEX/IIOTwoxNvvQHoLKm9ACV73TBOVVf+p2CKKvxUMDW1d1 Dj7vtZ1gl1QkZS661jwcyHrOa9Eyk8/lx7sFtsz0iEfP3jpiK/FeXnT5+NYDCQYIpG/t 1PGyMduh6pN/b2fijmF15OU445RNqUp8QQ5PLOl8DMSwRRs1pfe6SVCaysfMJdrxcGSR rG0uFWZnps7ERujCPIHSmN4shfVevdQs+aKC/IxEle0KIt8/KMbOMYTBdn+GyBU7g77f dcui2vX1PBbOTiZjJCNLBBiWJsnf4Z3qr8jIJFmRHMlPAa9utRfoz6mUW7ApDr/4PC95 HU1Q== MIME-Version: 1.0 X-Received: by 10.107.160.141 with SMTP id j135mr37981152ioe.43.1432055996756; Tue, 19 May 2015 10:19:56 -0700 (PDT) In-Reply-To: <555b6db8$0$12996$c3e8da3$5496439d@news.astraweb.com> References: <9ceklad15llnv3npejq9iuh91soci8aeqo@4ax.com> <555b0621$0$2753$c3e8da3$76491128@news.astraweb.com> <555b6db8$0$12996$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 20 May 2015 03:19:56 +1000 Subject: Re: Slices time complexity 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.20+ 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432055999 news.xs4all.nl 2921 [2001:888:2000:d::a6]:38703 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 5080 X-Received-Body-CRC: 291844058 Xref: csiph.com comp.lang.python:90875 On Wed, May 20, 2015 at 3:07 AM, Steven D'Aprano wrote: > True confession time: I've been using Python for over 15 years. For at least > 12 of those years, I've found myself feeling guilty every time I write a > loop like "for x in seq[1:]" to skip the first element, because I'm worried > about copying a huge list. Every single time I think "I really ought to > write a list view." And then I think about the effort involved (minor) > versus the benefit (even smaller) and I think "screw it, I'll just make a > copy". > > And in 12 years, this lazy "put off until tomorrow" attitude to list views > has failed me exactly *zero* times. I won't say You're Not Gonna Need It, > but I will say *I've* Never Needed It Yet. I can't think of many times when I've needed to do this on a large list - usually it's either a generic iterable handler (so it has to call iter() and then next(), and then iterate over what's left), or it's sys.argv. I literally cannot think of any other situation where I've iterated over seq[1:] than sys.argv. And if you're passing a million args to a program, frankly, you have more to worry about than the cost of trimming off the self-name to iterate over the rest of the args. Worries like, yaknow, actually doing some work with whatever was passed in as args, which is likely to dwarf the list slicing time. ChrisA