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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -