A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-March/051983.html below:

[Python-Dev] itemgetter/attrgetter extension

[Python-Dev] itemgetter/attrgetter extensionNick Coghlan ncoghlan at iinet.net.au
Thu Mar 10 12:19:16 CET 2005
Raymond Hettinger wrote:
> Any objections to extending itemgetter() and attrgetter() to be able to
> extract multiple fields at a time?
> 
>     # SELECT name, rank, serialnum FROM soldierdata
>     map(attrgetter('name', 'rank', 'serialnum'), soldierdata)
> 
>     # SELECT * FROM soldierdata ORDER BY unit, rank, proficiency
>     sorted(soldierdata, key=attrgetter('unit', 'rank', 'proficiency'))

Breaking the symmetry with getattr() bothers me a little, as does the signature 
change that occurs when multiple arguments are given (returning a tuple, whereas 
the single argument returns just the retrieved attribute).

For itemgetter, I'd like to see multiple arguments eventually map to 
multi-dimensional slices (to preserve symmetry with indexing syntax).

Call it -1 for itemgetter and -0 for attrgetter.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4