python - how to get index of a dictionary within a list -
test = [{"first" : "xyz", 'score': [1,2,3,4]},{"first" : "tests", 'score': [22,33,4]}]
i trying find xyz
in test , list scores of xyz
.
the index of dictionary not unique dictionaries hashed. need use keys access values in dictionary. small work-around can be:
>>> test = [{"first" : "xyz", 'score': [1,2,3,4]},{"first" : "tests", 'score': [22,33,4]}] >>> in test: # iterate through loop ... if i["first"] == 'xyz': # check if dict's value @ "first" ... print("the score {}".format(i["score"])) ... # print score ... [1, 2, 3, 4]
Comments
Post a Comment