I have a list of dictionaries with 2 keys: 'name' & 'value'. I need to get the value of 'value' key if value of 'name' key is 'Subject'
Currently i'm iterating through each dict and checking the value of 'name' and getting the value of 'value'. Is there any improved way of doing this ?
items = [
{
"name": "From",
"value": "from@example.com"
},
{
"name": "Date",
"value": "Tue, 8 Sep 2014 16:18:35 +0530"
},
{
"name": "Subject",
"value": "Test Subject"
},
{
"name": "To",
"value": "sender@example.com"
},
]
for item in items:
if item.get('name') == 'Subject':
print "Subject: " + item.get('value')