[Python-ideas] Adding list.pluck()

Mathias Panzenböck grosser.meister.morti at gmx.net
Sat Jun 2 21:54:56 CEST 2012

On 06/02/2012 08:50 PM, Westley Martínez wrote:
> On Sat, Jun 02, 2012 at 09:01:53PM +0300, Serhiy Storchaka wrote:
>> On 02.06.12 19:06, Guido van Rossum wrote:
>>> On Sat, Jun 2, 2012 at 8:54 AM, Mathias Panzenböck
>>> <grosser.meister.morti at gmx.net>   wrote:
>>>>>> >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.)
>> And this is not true in Python 3.
>> <map object at 0xb747970c>
> map returns a generator in Python 3.

Yes, yes. I opened a Python 2 shell to write the example code. Python 2 is still the default in most 
(all?) Linux distributions. To get a list from that just wrap list() around it.

I consider this behaviour (that map returns a generator) in fact superior to what's available in 
other languages. You can then pass that to whatever constructor you like (e.g. set() or tuple()) or 
take only some of the values and then stop without calculating (and allocating) it all.


More information about the Python-ideas mailing list