[issue31086] Add namedattrgetter function which acts like attrgetter but uses namedtuple

2017-07-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry Issac, but I'm going to decline this feature request. I know you're enthusiastic about this or some other variation but I don't think it is worthy of becoming part of the standard library. I do encourage you to post this somewhere as recipe (persona

[issue31086] Add namedattrgetter function which acts like attrgetter but uses namedtuple

2017-07-31 Thread Isaac Morland
Isaac Morland added the comment: Maybe the issue is that I work with SQL constantly. In SQL, if I say "SELECT a, b, c FROM t" and table t has columns a, b, c, d, e, f, I can still select a, b, and c from the result. So to me it is natural that getting a bunch of attributes returns something

[issue31086] Add namedattrgetter function which acts like attrgetter but uses namedtuple

2017-07-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: The principal use case for attrgetter() was to work with key-functions for sorted/min/max/groupby/nsmallest/nlargest. Secondarily, it worked nicely with map() and filter() as a field extractor in a chain of iterators. Neither these use cases would benefit

[issue31086] Add namedattrgetter function which acts like attrgetter but uses namedtuple

2017-07-30 Thread Isaac Morland
Isaac Morland added the comment: Here is the diff. Note that I assume implementation of #31085, which allows me to push determination of a name for the namedtuple down into namedtuple itself: diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 62cf708..d507d23 100644 -

[issue31086] Add namedattrgetter function which acts like attrgetter but uses namedtuple

2017-07-30 Thread Isaac Morland
New submission from Isaac Morland: This is meant to replace my proposal in #30020 to change attrgetter to use namedtuple. By creating a new function implemented in Python, I avoid making changes to the existing attrgetter, which means that both the need of implementing a C version and the ris