Suppose I have this:
list = [ { 'p1':'v1' } ,{ 'p2':'v2' } ,{ 'p3':'v3' } ]
I need to find p2 and get its value.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If this is what your actual code looks like (each key is unique), you should just use one dictionary:
You can convert a list of dictionaries to one dictionary by merging them with
update(but this will overwrite duplicate keys):If that’s not possible, you’ll need to just loop through them:
If you expect multiple results, you can also build up a list:
Also, I wouldn’t recommend actually naming any variables
dictorlist, since that will cause problems with the built-indict()andlist()functions.