I have this simple program:
x = {}
x[1,2] = 3
print x
print x[1,2]
It works fine. The fist print
generates {(1,2):3}
and the second one generates 3
.
But in my "big" program I seems to do the same but get a list indices must be integers, not tuple
error. What this error message can mean and how I can resolve this problem?
If you're getting that error, then you are trying to index a list, and not a dictionary.
A Python list, like [1, 2, 3]
, must be indexed with integer values. A dictionary, which is what you have in your example, can be indexed by a wider range of different values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With