Disclaimer: I am new the python programming (only 2 days experience)
alist=[{'a':'1a', 'b':'1b'},{'a':'2a','b':'2b'}, {'a':'3a','b':'3b'}]
How can I write a comprehension to extract all values of key='a'?
The following works but I just hacked until I got what I want. Not a good way to learn.
[alist['a'] for alist in alist if 'a' in alist]
in the comprehension I have been trying to use if key='a' in alist else 'No data'
Thank you for your help in advance
alist
as the loop variable.[item['a'] for item in alist if 'a' in item]
is clearer. – John La Rooy Jul 10 '13 at 3:11