[Python-ideas] Adding list.pluck()
masklinn at masklinn.net
Sat Jun 2 16:54:44 CEST 2012
On 2 juin 2012, at 07:25, Cenk Altı <cenkalti at gmail.com> wrote:
> If the item has definded a method "__getitem__" it will be called,
> else "__getattribute__" is called.
That is complète insanity and goes against pretty much all existing python code. Some types make keys available as both items and attributes but I do not know of any operation which does so.
> I know list comprehensions are same thing but .pluck seems easier to
> read and write I think (no need to write a temporary variable in list
> comprehension, and also square brackets). Just an idea...
Not a useful one, if you dislike the iteration variable of comprehensions you may use 'map' with itemgetter or attrgetter. Not to mention they are more flexible than pluck (they can extract multiple items or attributes, and attrgetter supports "deep" dotted paths)
More information about the Python-ideas