Here is a non-list method for functional programming fans
>>> alist=[{'a':'1a', 'b':'1b'},{'a':'2a','b':'2b'}, {'a':'3a','b':'3b'}] >>> from operator import itemgetter >>> list(map(itemgetter('a'), alist)) ['1a', '2a', '3a']
To get "No data", itβs much easier to use list comprehension.
>>> [item.get('a', 'No Data') for item in alist] ['1a', '2a', '3a']
This works because dict.get allows dict.get to specify a default argument if the key is not found.
source share