array of integers != integer
list indices must be integers - you've given a list of integers.
You probably want a list comprehension:
newarray = [ colors[i] for i in c ]
But you really ought to learn the language properly before using it. It's not like python takes a long time to learn.
EDIT:
If you're still getting the same error then your assertion that c
is a list of integers is incorrect.
Please try:
print type(c)
print type(c[0])
print type(colors)
print type(colors[0])
Then we can work out what types you have got. Also a short but complete example would help, and probably teach you a lot about your problem.
EDIT2:
So if c
is actually a list of string, you should probably have mentioned this, strings don't get automatically converted to integers, unlike some other scripting languages.
newarray = [ colors[int(i)] for i in c ]
EDIT3:
Here is some minimal code that demonstrates a couple of bug fixes:
x=["1\t2\t3","4\t5\t6","1\t2\t0","1\t2\t31"]
a=[y.split('\t')[0] for y in x]
b=[y.split('\t')[1] for y in x]
c=[y.split('\t')[2] for y in x] # this line is probably the problem
colors=['#FFFF00']*32
newarray=[colors[int(i)] for i in c]
print newarray
a) colors
needs to be 32 entries long.
b) the elements from c (i
) in the list comprehension need to be converted to integers (int(i)
).