Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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; 'example:': 0.03; 'skip:[ 20': 0.03; 'desirable.': 0.07; 'empty,': 0.09; 'slices': 0.09; 'subject:()': 0.09; 'cc:addr:python-list': 0.10; '9:20': 0.16; 'oct': 0.16; 'reversed': 0.16; 'subject:array': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'obviously': 0.18; 'saying': 0.18; '>>>': 0.18; 'cc:2**0': 0.23; "python's": 0.23; 'this:': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'andrew': 0.27; 'list:': 0.27; 'message- id:@mail.gmail.com': 0.27; 'though.': 0.29; 'worked': 0.30; 'code': 0.31; 'asking': 0.32; 'getting': 0.33; 'turns': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'useful': 0.36; 'october': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'instead': 0.39; 'header:Received:5': 0.40; 'skip:a 30': 0.60; 'skip:n 10': 0.63; 'oscar': 0.84; 'stop,': 0.84; 'do:': 0.91 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 :cc:content-type; bh=x6iMwm3hc/ggJ6bmHgr5jo0uDjp9q3Ck6vzcCzVSmko=; b=l92ueqgyshC/XEJBtL2tk9NOw9xIOI6Mk08MCGMm1iauWIsSM/4wNT3knEPJV7FUL5 2HrnlmHn0lA5wJw3RdjPXOLIDWHP9hYyLHMr9RaKZNQp+1NvcHm21qqnnCD77SgV1Mdq aKkUWr9M1gc09Hg6d82aQeFF6Wn5FmTI/NaCiX6wyN4Nn2k0MoL0oDGH7kFN95jKxjp8 JGFrAIEFwahy4WZA+O+6ky4lNcJk3b7j+N1MDjudWonMKLoH0qd2n6YI2VFgiU9WFO/3 cG1xphRvKA45vrP1WR/mG1D4gelIwEoKPvPwV2CYosEK2L5V4TpSsOlmwgiOLl+ota1c 54Xw== MIME-Version: 1.0 In-Reply-To: References: <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> <508e6649$0$29967$c3e8da3$5496439d@news.astraweb.com> <508E9EBA.2070307@r3dsolutions.com> Date: Tue, 30 Oct 2012 00:04:22 +0000 Subject: Re: Negative array indicies and slice() From: Oscar Benjamin To: Ian Kelly Content-Type: text/plain; charset=ISO-8859-1 Cc: Python 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351555464 news.xs4all.nl 6859 [2001:888:2000:d::a6]:39746 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32445 On 29 October 2012 23:01, Ian Kelly wrote: > On Mon, Oct 29, 2012 at 9:20 AM, Andrew Robinson > wrote: >> FYI: I was asking for a reason why Python's present implementation is >> desirable... >> >> I wonder, for example: >> >> Given an arbitrary list: >> a=[1,2,3,4,5,6,7,8,9,10,11,12] >> >> Why would someone *want* to do: >> a[-7,10] >> Instead of saying >> a[5:10] or a[-7:-2] ? > > A quick search of local code turns up examples like this: > > if name.startswith('{') and name.endswith('}'): > name = name[1:-1] > > If slices worked like ranges, then the result of that would be empty, > which is obviously not desirable. > > I don't know of a reason why one might need to use a negative start > with a positive stop, though. It's useful when getting a reversed slice: >>> a = [1,2,3,4,5,6,7,8,9,10] >>> a[-3:3:-1] [8, 7, 6, 5] Oscar