You start your day, happily working with dictionaries…Life is good.
>>> mydict = {'key-a': 'value-a', 'key-b': 'value-b'} >>> mydict['key-a'] 'value-a'
All of a sudden, storm clouds appear. Your dictionary variable accidentally gets assigned a list, and life is no longer good!
>>> mydict = {'key-a': 'value-a', 'key-b': 'value-b'} >>> mydict['key-a'] 'value-a' >>> mydict = [] >>> mydict['key-a'] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers
The error message "TypeError: list indices must be integers" is generated when you attempt to use a non-int for a index inside the [] operator.
By the way, almost the same message is used if you do this with a tuple:
TypeError: tuple indices must be integers