Suppose I have the following list of dictionaries:
months = [
{'id':'001','date':'January'},
{'id':'002','date':'February'},
{'id':'003','date':'March'},
{'id':'004','date':'April'},
{'id':'005','date':'May'},
{'id':'006','date':'June'},
{'id':'007','date':'July'},
{'id':'008','date':'August'},
{'id':'009','date':'September'},
{'id':'010','date':'October'},
{'id':'011','date':'November'},
{'id':'012','date':'December'},
]
If the user enters the month as January, he should get the ID as 001.
I tried this, but it returns me a list of Months only.
res = [ mon['date'] for mon in months]
I need the id directly from the key itself. How can I achieve that ?