list Integer indexing dies??
Ishwor
ishwor.gurung at gmail.com
Thu Dec 23 09:15:54 EST 2004
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??
>>> l = [1,2,3]
>>> l[0]
1
>>> l[0][0]
Traceback (most recent call last):
File "<pyshell#244>", line 1, in -toplevel-
l[0][0]
TypeError: unsubscriptable object
>>> l[0]
1
>>> 1[0]
Traceback (most recent call last):
File "<pyshell#246>", line 1, in -toplevel-
1[0]
TypeError: unsubscriptable object
>>>
The compiler reports unsubscriptable object ?? confused , dazzled i am ???!!??
The same list now holds integer instead of strings and l[0][0][0]
which worked fine earlier on strings doesn't seem to work on
integers???
Any help is greatly appreciated.
--
cheers,
Ishwor Gurung
More information about the Python-list
mailing list