On 24/11/2015 13:25, Cai Gengyang wrote:

results = [
{"id": 1, "name": "ensheng", "score": 10},
{"id": 2, "name": "gengyang", "score": 12},
{"id": 3, "name": "jordan", "score": 5},
]

I want to find gengyang's score. This is what I tried :

print((results["gengyang"])["score"])

but I got an error message instead :

Traceback (most recent call last):
   File "<pyshell#62>", line 1, in <module>
     print((results["gengyang"])["score"])
TypeError: list indices must be integers, not str

Any ideas how to solve this? Thank you ..


Please read and digest the TypeError. There is a very strong hint in there, follow it. Compare the type of your data structure `results` with the one you've used earlier today. Spot the difference?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to