Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92010

Re: How to access the low digits of a list

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.035
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'builtin': 0.07; 'indices': 0.07; 'subject:How': 0.09; 'len(x)': 0.09; 'slices': 0.09; 'index': 0.13; 'wed,': 0.15; 'selects': 0.16; 'sequence.': 0.16; 'subject:access': 0.16; 'wrote:': 0.16; 'am,': 0.23; '2015': 0.23; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'raise': 0.24; 'least': 0.27; 'sequence': 0.27; 'message-id:@mail.gmail.com': 0.28; 'subject:list': 0.28; 'implied': 0.29; 'types.': 0.29; 'certainly': 0.31; "can't": 0.32; 'url:python': 0.33; 'rule': 0.33; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'thanks': 0.36; 'url:library': 0.36; 'subject:: ': 0.37; 'tue,': 0.38; 'means': 0.39; 'pm,': 0.39; 'enough': 0.39; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'sure': 0.40; 'subject:the': 0.40; 'url:3': 0.60; 'learn': 0.60; 'even': 0.61; 'entire': 0.61; 'matter': 0.63; 'above,': 0.63; 'stated': 0.70; 'to:name:python': 0.84; 'utc+5:30,': 0.84; 'visually': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=UMhaRwmrsad35Aj0TlTYqss7wAh3S4l59c7yJktnDbA=; b=j+Phw8wKNTYBnex04ySpnTgjzjqafbPkWgonAzAhsVfUWPOMNvWY3inME8T13UYERm VWX7Em/zW1Q0FxWrIfIsXqK57DS+TquCeqdBsqwpnx/qPA+md/5Wn3R2imeCs9qgXYuG /myqKJy90MYmbx+g+IgRRWun16h8mxwoP9c0bPc/OfPMZ7dgvml+mM5zqOLpc9ljzu++ a6bZOsLP83bL7Glh30ArbpepP2o5x+R3kNVMFDxeIIoFbRzAPPHzR5Z+KS5sEZS4zE05 WQLO+K8B73yw+gP6+N9qbf6iOWQQt8gQwvlAwkUGBHeGvyQiTCwaJRRXvZ71ukgABY6n HQ6A==
X-Received by 10.42.72.132 with SMTP id o4mr1121290icj.20.1433371021781; Wed, 03 Jun 2015 15:37:01 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <11005554-e89f-407c-8720-fae1bb3fced8@googlegroups.com>
References <efe9d48e-9aaf-4e68-aa26-c83da32e80f5@googlegroups.com> <18a4709f-47c8-41f7-87d5-08bbb00166b6@googlegroups.com> <mailman.63.1433254823.13271.python-list@python.org> <11005554-e89f-407c-8720-fae1bb3fced8@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 3 Jun 2015 16:36:21 -0600
Subject Re: How to access the low digits of a list
To Python <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.137.1433371024.13271.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433371024 news.xs4all.nl 2910 [2001:888:2000:d::a6]:39760
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92010

Show key headers only | View raw


On Wed, Jun 3, 2015 at 3:08 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Tuesday, June 2, 2015 at 7:50:58 PM UTC+5:30, Ian wrote:
>> On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody  wrote:
>> > For that matter even this works
>> > But I am not sure whats happening or that I like it
>> >
>> >>>> [x[-2:]  for x in lines]
>> > ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00']
>>
>> x[-2:] selects all items in the sequence with index i such that len(x)
>> - 2 <= i < len(x). For a sequence of length 2 or less, that's the
>> entire sequence.
>
> Thanks -- learn something
> So it means that indices can give indexerror; slices cannot?
> Seems fair enough put that way, but is visually counterintuitive

Yes. The rule I paraphrased above is stated at
https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
-- scroll down to note 4. I don't know if there's anything that
clearly states that sequence slicing can't raise IndexError, but it is
at least implied by the above, and it is certainly true of all builtin
sequence types.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to access the low digits of a list fl <rxjwg98@gmail.com> - 2015-06-02 05:23 -0700
  Re: How to access the low digits of a list Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-02 08:32 -0400
  Re: How to access the low digits of a list Frank Stutzman <stutzman@cat2.kjsl.com> - 2015-06-02 12:34 +0000
  Re: How to access the low digits of a list Rustom Mody <rustompmody@gmail.com> - 2015-06-02 05:35 -0700
    Re: How to access the low digits of a list Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 08:19 -0600
      Re: How to access the low digits of a list Rustom Mody <rustompmody@gmail.com> - 2015-06-03 14:08 -0700
        Re: How to access the low digits of a list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 22:41 +0100
        Re: How to access the low digits of a list Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-03 16:36 -0600
        Re: How to access the low digits of a list Steven D'Aprano <steve@pearwood.info> - 2015-06-04 23:27 +1000
  Re: How to access the low digits of a list Steven D'Aprano <steve@pearwood.info> - 2015-06-03 01:11 +1000

csiph-web