Re: How to access the low digits of a list

2015-06-04 Thread Steven D'Aprano
On Thu, 4 Jun 2015 07:08 am, Rustom Mody wrote: > So it means that indices can give indexerror; slices cannot? If you write your own class with a __getitem__ method, you can have it do anything you like, including raise an exception. Built-in sequence types like list, str and tuple, however, all

Re: How to access the low digits of a list

2015-06-03 Thread Ian Kelly
On Wed, Jun 3, 2015 at 3:08 PM, Rustom Mody 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

Re: How to access the low digits of a list

2015-06-03 Thread Mark Lawrence
On 03/06/2015 22:08, Rustom Mody 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',

Re: How to access the low digits of a list

2015-06-03 Thread Rustom Mody
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'

Re: How to access the low digits of a list

2015-06-02 Thread Steven D'Aprano
On Tue, 2 Jun 2015 10:23 pm, fl wrote: > I don't know whether there is a way to know the length of lines[3]. The same way as to know the length of anything else: len(x) # the length of x len("hello") # the length of "hello" len(lines[3]) # the length of lines[3] > Then, > I can use a -1 ste

Re: How to access the low digits of a list

2015-06-02 Thread Ian Kelly
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

Re: How to access the low digits of a list

2015-06-02 Thread Rustom Mody
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', '

Re: How to access the low digits of a list

2015-06-02 Thread Frank Stutzman
fl wrote: ---snip 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' > l

Re: How to access the low digits of a list

2015-06-02 Thread Joel Goldstick
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

How to access the low digits of a list

2015-06-02 Thread fl
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 d