I have a list that looks like
[{'name': 'red', 'test':4},... {'name': 'reded', 'test':44}]`
I have a name (for example: reded
) and I want to find the dictionary in the list above that has name
in the dictionary set to reded
. What is a concise way of doing so?
My attempts look something similar to
x = [dict_elem for dict_elem in list_above if dict_elem['name']==reded]
Then I do
final_val = x[0]
if the name gets matched. This can also be done with a for loop
but it just seems like there is a simple one-liner for this. Am I missing something?