returning values of a particular key from a dictionary

Paul Rubin http
Fri May 1 05:00:42 EDT 2009


Saurabh <phonethics at gmail.com> writes:
> arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'})
> print foo(arr, 'y')
> ['a','b','c']

print list(a['y'] for a in arr)



More information about the Python-list mailing list