list Integer indexing dies??
Ishwor
ishwor.gurung at gmail.com
Thu Dec 23 11:29:40 EST 2004
On 23 Dec 2004 15:05:20 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> Op 2004-12-23, Ishwor schreef <ishwor.gurung at gmail.com>:
> > 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]
>
> Well if it should become valid, it should just return 123232 IMO.
>
Im not sure i understand u but what i meant was that
>>> 123 + 2
125 # nice n good
now it would be nice if integer could also be *subscripted* too
>>> 123[0] + 2
3
;-) But as i said in earlier post said, i'll stick with import this's
#2 by Tim Peters. Its better to leave these design issues with other
**senior pythoneers**.
> > in which basically python can infer from the object type and print out
> > 1 instead of coughing up those errors?
>
> Why do you feel it should cough up 1?
>
>>>123232[0] #hypothetical 0th position in the integer.
1
> Suppose I write a number in octal notation.
>
> What should 035[0] cough up? Be carefull it should
>>>035[0]
3 # my own opinion.
> cough up the same as 29[0].
>>>29[0]
2 #again my own opinion
[snip]
> by starting indexing from the back we get a nice correspondence between
> the index of the number and the power of 10 it represents.
>
> --
> Antoon Pardon
> --
> http://mail.python.org/mailman/listinfo/python-list
>
As in my view if python could treat object in context sensitive
manner, it would be better world but its just my own beginners
opinion.
Happy hunting with Python. ;-)
--
cheers,
Ishwor Gurung
More information about the Python-list
mailing list