Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'elements.': 0.05; 'initialize': 0.05; 'chunk': 0.07; 'defines': 0.07; 'python': 0.09; '*end*': 0.09; 'array.': 0.09; 'behavior,': 0.09; 'indexes': 0.09; 'integers': 0.09; 'pointers': 0.09; 'subject:()': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'programmer': 0.11; 'index': 0.13; 'do,': 0.15; "'c'": 0.16; "'c',": 0.16; '10:00': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'know;': 0.16; 'level;': 0.16; 'merely': 0.16; 'oct': 0.16; 'ranges.': 0.16; 'routinely': 0.16; 'subject:array': 0.16; 'thought.': 0.16; 'twice.': 0.16; 'xrange': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'issue,': 0.17; 'pointer': 0.17; 'written,': 0.17; 'memory': 0.18; 'variable': 0.20; 'equivalent': 0.20; 'skip:= 20': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'elements': 0.23; 'script': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'values': 0.26; 'question': 0.27; 'andrew': 0.27; 'important.': 0.27; 'replace': 0.27; 'actual': 0.28; 'arrays': 0.29; 'equivalent.': 0.29; 'fast.': 0.29; 'writes:': 0.29; 'array': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'classes': 0.30; 'expect': 0.31; 'lists': 0.31; 'code': 0.31; 'could': 0.32; 'anyone': 0.33; 'know.': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'clear': 0.35; 'so,': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'really': 0.36; 'created': 0.36; 'but': 0.36; 'alone': 0.36; 'data.': 0.36; 'thank': 0.36; 'itself': 0.37; 'october': 0.37; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'passed': 0.37; 'received:209': 0.37; 'far': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'nothing': 0.38; 'possible.': 0.38; 'where': 0.40; 'think': 0.40; 'your': 0.60; 'stand': 0.61; 'maximum': 0.63; 'skip:n 10': 0.63; 'more': 0.63; 'show': 0.63; 'fact,': 0.69; 'notice:': 0.71; 'contrary': 0.71; 'obvious': 0.71; 'ranges': 0.71; 'actually,': 0.84; 'flexible,': 0.84; 'ian,': 0.84; 'you;': 0.84 Newsgroups: comp.lang.python Date: Mon, 29 Oct 2012 00:54:29 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=207.55.87.38; posting-account=PPUdCwoAAABL5SHTC0kNfTVCKKHjc2Wa References: <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 207.55.87.38 MIME-Version: 1.0 Subject: Re: Negative array indicies and slice() From: Andrew To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: , Message-ID: Lines: 71 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351497278 news.xs4all.nl 6952 [2001:888:2000:d::a6]:48410 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32346 On Sunday, October 28, 2012 9:26:01 PM UTC-7, Ian wrote: > On Sun, Oct 28, 2012 at 10:00 PM, Andrew wrote: >=20 > > Hi Ian, >=20 > > Well, no it really isn't equivalent. >=20 > > Consider a programmer who writes: >=20 > > xrange(-4,3) *wants* [-4,-3,-2,-1,0,1,2] >=20 > > >=20 > > That is the "idea" of a range; for what reason would anyone *EVER* want= -4 to +3 to be 6:3??? >=20 >=20 >=20 > That is what ranges do, but your question was about slices, not ranges. Actually, I said in the OP: "I also don't understand why slice() is not equivalent to an iterator, but = can replace an integer in __getitem__() whereas xrange() can't." =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thank you for the code snippet; I don't think it likely that existing progr= ams depend on nor use a negative index and a positive index expecting to ta= ke a small chunk in the center... hence, I would return the whole array; Or= if someone said [-len(listX) : len(listX)+1 ] I would return the whole arr= ay twice. That's the maximum that is possible. If someone could show me a normal/reasonable script which *would* expect th= e other behavior, I'd like to know; compatibility is important. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D My intended inferences about the iterator vs. slice question was perhaps no= t obvious to you; Notice: an iterator is not *allowed* in __getitem__(). The slice class when passed to __getitem__() was created to merely pass tw= o numbers and a stride to __getitem__; As far as I know slice() itself doe= s *nothing* in the actual processing of the elements. So, it's *redundant*= functionality, and far worse, it's restrictive. The philosophy of Python is to have exactly one way to do something when po= ssible; so, why create a stand alone class that does nothing an existing cl= ass could already do, and do it better ? A simple list of three values would be just as efficient as slice()! xrange is more flexible, and can be just as efficient. So, Have I misunderstood the operation of slice()? I think I might have...= but I don't know. In 'C', where Python is written, circularly linked lists -- and arrays are = both very efficient ways of accessing data. Arrays can, in fact, have nega= tive indexes -- perhaps contrary to what you thought. One merely defines a= variable to act as the base pointer to the array and initialize it to the = *end* of the array. Nor is the size of the data elements an issue, since in= Python all classes are accessed by pointers which are of uniform size. I r= outinely do this in C. Consider, also, that xrange() does not actually create a list -- but merely= an iterator generating integers which is exactly what __getitem__ works on= . So, xrange() does not need to incur a memory or noticeable time penalty. >From micro-python, it's clear that their implementation of xrange() is at t= he 'C' level; which is extremely fast.