Getting "TypeError:list indices must be integers"
John Machin
sjmachin at lexicon.net
Tue Jun 13 04:00:33 EDT 2006
On 13/06/2006 5:33 PM, Girish Sahani wrote:
> Python prints 'c','c' when i print repr(index1),repr(index2).This means
> they are characters right??
> But i have defined indexList as follows (and also tested the output, both
> are outputted as lists of numbers):
>
> for char in list1:
> i = substring1.index(c)
That would be "char", I presume, not "c".
> indexList1.append(i)
>
> for char in list2:
> j = substring2.index(char)
> indexList2.append(j)
>
> (substring1 and substring2 are 2 different strings)
>
> Then i'm iterating over indexList1 and indexList2, so i fail to understand
> why i am getting the typeError....
>
>
>> On 13/06/2006 5:08 PM, John Machin wrote:
>>> On 13/06/2006 4:11 PM, Girish Sahani wrote:
[SNIPPED]
Girish,
Could we please abide by the Geneva Convention:
1. Please don't top-post.
2. Please don't type what you thought was in your code; copy/paste
actual most-recently-executed code.
3. Please reply to the newsgroup/mailing-list -- I've taken the liberty
of dragging this back there as there appears to be no private content ...
OK, so you've found that index1 and index2 each contain 'c'. Despite
your belief that they should contain the results of
some_string.index(some_char), the only reasonable hypothesis is that
somebody is polluting the water further upstream. Who is that somebody?
The usual and only suspect is *you*. Please go away and sprinkle print
statements at likely spots further upstream until you have found the
problem.
Kindest possible regards,
John
More information about the Python-list
mailing list