[Python-ideas] Adding list.pluck()

Guido van Rossum guido at python.org
Sat Jun 2 18:06:56 CEST 2012


Forgive the out of context drive-by comments...

On Sat, Jun 2, 2012 at 8:54 AM, Mathias Panzenböck
<grosser.meister.morti at gmx.net> wrote:
> There are already at least two easy ways to do this:
>
>>>> stooges=[{'name': 'moe', 'age': 40}, {'name': 'larry', 'age': 50},
>>>> {'name': 'curly', 'age': 60}]
>>>> [guy['name'] for guy in stooges]
> ['moe', 'larry', 'curly']

Bingo. Doesn't need improvements.

>>>> from operator import itemgetter
>>>> map(itemgetter('name'),stooges)
> ['moe', 'larry', 'curly']

If I saw this I would have to think a lot harder before I figured what
it meant. (Especially without the output example.)

Let's remember KISS.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list