returning values of a particular key from a dictionary
Chris Rebert
clp2 at rebertia.com
Fri May 1 05:05:58 EDT 2009
On Fri, May 1, 2009 at 1:53 AM, Saurabh <phonethics at gmail.com> 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)
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list