Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why list indices must be integers, not tuple?

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?

like image 319
Roman Avatar asked Nov 30 '22 17:11

Roman


1 Answers

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.

like image 159
unwind Avatar answered Dec 08 '22 16:12

unwind