my list has value such as
m=[['na','1','2']['ka','31','45']['ra','3','5']
d=0
r=2
t=m[d][r]
print t # this is givin number i.e 2
Now when I use this value
u=[]
u=m[t]
I am getting an err msg saying type error list does t开发者_StackOverflow社区ake str values...
i want to use like this how can i convert that t into a integer??
please suggest..
thanks..
Your problem is that you can't index into a list using a string. To convert t
to an integer use int
:
u=m[int(t)]
Use int(t)
as the index, not t
itself, since t
is a string and to index a variable you need an integer, not a string, as the error message is telling you.
精彩评论