I have a list below, and I'm trying to have a lambda function to retrieve 'cat' value from the list when 'prop' equals to a given string.
a=[{'prop':'ABC','cat':'ABC Dir'}, {'prop':'DEF','cat':'DEF Dir'}, ...]
I have successfully got a List Comprehension, which gives me expected 'ABC Dir' if I feed in 'ABC', but I failed to convert it to a lambda function if possible. Advise is appreciated.
>>> aa=[x['cat'] for x in a if x['prop'] == 'ABC']
>>> aa
['ABC Dir']
expected result:
>>>bb('ABC')
'ABC Dir'
>>>bb('DEF')
'DEF Dir'
bb()is not a lambda function.