Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2a.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:How': 0.09; 'slices': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; '(starting': 0.16; 'digits.': 0.16; 'subject:access': 0.16; 'versatile': 0.16; 'wrote:': 0.16; 'thanks,': 0.19; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'am,': 0.23; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.28; 'subject:list': 0.28; 'end,': 0.29; 'notation': 0.29; 'lines': 0.30; 'that.': 0.30; 'url:mailman': 0.31; 'url:python': 0.33; 'received:google.com': 0.34; 'url:listinfo': 0.35; 'list:': 0.35; 'really': 0.35; 'step': 0.36; 'too': 0.36; 'url:org': 0.36; 'there': 0.36; 'two': 0.37; 'hi,': 0.37; 'should': 0.37; 'subject:: ': 0.37; 'tue,': 0.38; 'or,': 0.38; 'end': 0.39; 'means': 0.39; 'subject:the': 0.40; 'to:none': 0.90; 'joel': 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:cc :content-type; bh=HzPNrNJSSR6O/uLLHrnJtjjKlmG68RNrk4Z12q5G/Ak=; b=gLCKkc2kIbsB2m7GPlOkLKD5Tm8ifp1tPRsKaIdRlkJd7BlqSi/j73RwUnS+gZsjSf T6r5BPFTkVtO+Jhkz+pxv1o9JexYYR+NuuNQ1b+ldN9/7AiEoC909AD6sLmQlO+2OMf9 yVWYiENHIVx/MxbYl05nNSENQJpr0UB+fGGTx7aZ1sOW78snGzYFET60A8yVKz9m3dOm meZoh0a2z11C7MDZ5IMV6rsEHv7+lzKnI62FuH3nrLCWcG7ZeHogAXcG1DMLTMLDQm+7 lkxWaeAtteGw5c1Wy40J+PXj6mPepGoRh3x0cJWtfV5OwolmnncImqdp8+hvHSZRR3OC hgcQ== MIME-Version: 1.0 X-Received: by 10.50.61.234 with SMTP id t10mr19889880igr.19.1433248320622; Tue, 02 Jun 2015 05:32:00 -0700 (PDT) In-Reply-To: References: Date: Tue, 2 Jun 2015 08:32:00 -0400 Subject: Re: How to access the low digits of a list From: Joel Goldstick Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433248322 news.xs4all.nl 2929 [2001:888:2000:d::a6]:55489 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91828 On Tue, Jun 2, 2015 at 8:23 AM, fl wrote: > Hi, > > I have a list: > > > > > > >>>> lines > ['12', '42', '49', '156', '225', '36', '49', '164', '11181', '3100'] > > > > I want to access the last two digits. That is: > > ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] > > > When I try to use lines[3][0] is '1' > lines[3][1] is '5' > lines[3][2] is '6' > > > I don't know whether there is a way to know the length of lines[3]. Then, I > can use a -1 step to get the last two digits. Or, you may have much better > ways to do that. Python is really too versatile I feel. > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list You should read about slices lines[3][-2:] will give the last two characters in the 3rd group (starting from 0) The notation means to start with 2 from the end, and proceed to the end -- Joel Goldstick http://joelgoldstick.com