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
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