Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'keys,': 0.07; 'received:64.202.165': 0.07; 'logic': 0.09; 'slices': 0.09; 'subject:()': 0.09; 'constructs': 0.16; 'iterator': 0.16; 'operation,': 0.16; 'operation.': 0.16; 'slicing,': 0.16; 'subject:array': 0.16; 'wrote:': 0.17; 'sort': 0.21; 'thanks.': 0.21; 'produces': 0.22; 'so.': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'wonder': 0.27; 'chris': 0.28; 'generally': 0.32; 'quickly': 0.32; 'curious': 0.33; 'like:': 0.33; 'values.': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'compared': 0.35; 'faster': 0.35; 'similar': 0.35; 'something': 0.35; 'but': 0.36; 'does': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'more': 0.63; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'thing,': 0.84 Date: Sun, 28 Oct 2012 21:52:02 -0700 From: Andrew Robinson User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111126 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Negative array indicies and slice() References: <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> <508e6649$0$29967$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: andrew3@r3dsolutions.com 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: 1351511636 news.xs4all.nl 6945 [2001:888:2000:d::a6]:43050 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32363 On 10/29/2012 04:32 AM, Chris Angelico wrote: > I wonder if what the OP is looking for is not slicing, but something > more akin to map. Start with a large object and an iterator that > produces keys, and create an iterator/list of their corresponding > values. Something like: a=[1,2,3,4,5,6,7,8,9,10] b=[a[i] for i in > xrange(-4,3)] It's not strictly a slice operation, but it's a similar > sort of thing, and it can do the wraparound quite happily. ChrisA A list comprehension ? That does do what I am interested in, *very* much so. Quite a gem, Chris! :-\ 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] ] But, unless it were grossly slower -- so that if/then logic and slices were generally faster -- I will use it. Thanks. --Andrew.