returning values of a particular key from a dictionary

Chris Rebert clp2 at
Fri May 1 11:05:58 CEST 2009

On Fri, May 1, 2009 at 1:53 AM, Saurabh <phonethics at> wrote:
> arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'})
> print foo(arr, 'y')
> ['a','b','c']
> I can write the function foo to return ['a','b','c'].
> Is there some 'automatic'/built-in way to get this in Python ?

from operator import itemgetter
print map(itemgetter("y"), arr)


More information about the Python-list mailing list