list Integer indexing dies??

Ishwor ishwor.gurung at gmail.com
Thu Dec 23 09:47:05 EST 2004


On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> Op 2004-12-23, Ishwor schreef <ishwor.gurung at gmail.com>:
> > Hi all. Look at this snippet of code.
> >
> >>>> l = ['a','b','c','d']
> >>>> l
> > ['a', 'b', 'c', 'd']
> >>>> l[0][0][0]
> > 'a'
> > It prints the value 'a'. Fine so far :-)
> > l[0] ---> 'a' .
> > l[0][0]---> 'a'[0] --> 'a'.
> > l[0][0][0] ---> 'a'[0][0] --> 'a'[0] --> 'a'
> >
> > Now why doesnt this list which holds integer seem to work??
> 
> Because this only works with strings.
> 
> String is the only object in python which has an implied
> equivallence between an element and a squence of one.
> 
> So one character is a string and a string is a sequence
> of characters.
> 
> So 'a'[0] is again 'a' which can again be indexed by
> 0 as many times as you want.

;-) gotcha. But shouldn't this be valid too?? 
>>> 123232[0] 
in which basically python can infer from the object type and print out
1 instead of coughing up those errors? My experience as a learner here
is that there should be some automagics  & say like "okay you want to
do indexing on integers ( context dependent); i'll give you the index
of 0th position in that integer" ???
 

[snip]

Thanks Antoon.
-- 
cheers,
Ishwor Gurung



More information about the Python-list mailing list