Finding scores from a list

Cai Gengyang gengyangcai at gmail.com
Tue Nov 24 08:25:28 EST 2015


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 ..



More information about the Python-list mailing list