Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91830
| X-Received | by 10.182.28.99 with SMTP id a3mr35803614obh.18.1433248504061; Tue, 02 Jun 2015 05:35:04 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.82.8 with SMTP id e8mr233335igy.7.1433248504034; Tue, 02 Jun 2015 05:35:04 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h15no1101648igd.0!news-out.google.com!n7ni50895igk.0!nntp.google.com!h15no1101642igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Tue, 2 Jun 2015 05:35:03 -0700 (PDT) |
| In-Reply-To | <efe9d48e-9aaf-4e68-aa26-c83da32e80f5@googlegroups.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=117.195.32.231; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui |
| NNTP-Posting-Host | 117.195.32.231 |
| References | <efe9d48e-9aaf-4e68-aa26-c83da32e80f5@googlegroups.com> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <18a4709f-47c8-41f7-87d5-08bbb00166b6@googlegroups.com> (permalink) |
| Subject | Re: How to access the low digits of a list |
| From | Rustom Mody <rustompmody@gmail.com> |
| Injection-Date | Tue, 02 Jun 2015 12:35:04 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:91830 |
Show key headers only | View raw
On Tuesday, June 2, 2015 at 5:53:34 PM UTC+5:30, 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. len(lines[3]) ?? You can do this: [Hope I am not doing your homework!] >>> [(x[-2:] if len(x) > 2 else x) for x in lines] ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] >>> 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'] >>>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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