Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'part,': 0.09; 'subject:()': 0.09; '"good': 0.16; 'constructs': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oct': 0.16; 'operation.': 0.16; 'readability.': 0.16; 'subject:array': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'header:In-Reply-To:1': 0.25; 'andrew': 0.27; 'message-id:@mail.gmail.com': 0.27; 'concern': 0.29; 'usually': 0.30; 'quickly': 0.32; 'cases,': 0.33; 'curious': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'whatever': 0.35; 'compared': 0.35; 'faster': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'yourself': 0.77 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:to :content-type; bh=t64afO6hTXL/L1EXLQHoZPchV/o6PZQ7bG+Zh+y1yRw=; b=IOO5Fo7JyTqcHbiAqz+N5/h5jh1xTrkcomipszs2txI736KTlvF/SjWG4iFckbwpFo PoR+XAZJi5gM4/6s8tnonoo1Aov3w2t7hjOB5cQD6LhkYwJ/R5cJEBNtoEVNMrw2zjv4 eZwWYWmCUzP4i9cARyotP2vez7BM1neFMJrEqA63+RdW29xk+q6B6DJKUmL+xSUmnkwe TgyrTZs/iO89tonfK23J19r4g9A4LBmxdUaN1U7fWuzUIZS03+s5aoQcAmR1Yer/uznL mhEbWku06pAaBHiqLWG3QiopiUSE9HU74hnHyIKWZi5cuCRybzlnRLT4VB+S9h3SDBn+ ftHA== MIME-Version: 1.0 In-Reply-To: <508E0B72.7040107@r3dsolutions.com> References: <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> <508e6649$0$29967$c3e8da3$5496439d@news.astraweb.com> <508E0B72.7040107@r3dsolutions.com> Date: Mon, 29 Oct 2012 23:40:53 +1100 Subject: Re: Negative array indicies and slice() From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351514456 news.xs4all.nl 6892 [2001:888:2000:d::a6]:33638 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32366 On Mon, Oct 29, 2012 at 3:52 PM, Andrew Robinson wrote: > I am curious as to how quickly it constructs the result compared to a slice > operation. > > Eg: > a[1:5] > vs. > [ a[i] for i in xrange[1:5] ] For the most part, don't concern yourself with performance. Go with functionality and readability. In the trivial case shown here, the slice is WAY clearer, so it should definitely be the one used; in other cases, the slice might simply be insufficient, so you go with whatever achieves your goal. Performance will usually be "good enough", even if there's a marginally faster way. ChrisA