Skip to content Skip to sidebar Skip to footer

Python - Typeerror: String Indices Must Be Integers

For some reason this piece of script is returning the error: 'TypeError: string indices must be integers'; and I cannot see what's wrong. Am I being stupid and overlooking an obvio

Solution 1:

I think you want it this way: definition = terms[term]

Solution 2:

This line definition = term[terms] is trying to get a character out of the string term. You probably just typoed, and want

definition = terms[term]
                 ^ here, reference the dict, not the string

Solution 3:

You are indexing the string term instead of the dictionary terms. Try:

definition = terms[term]

Solution 4:

You accidentally swapped the variables. Change this:

definition = term[terms]

To this:

definition = terms[term]

Post a Comment for "Python - Typeerror: String Indices Must Be Integers"