[Python-Dev] Re: "groupby" iterator
Raymond Hettinger
python at rcn.com
Wed Dec 3 10:27:49 EST 2003
> (This thread has nothing to do with the groupby iterator any more, but
> I'm loathe to change the subject since so many messages are already
> under this one.)
>
> (I've read quite a few messages posted after Greg's post, but Greg
> still summarizes the issue best for me, *and* it has an alternative
> idea that needs a response.)
I'm am still curious to hear your thoughts on the either sublime or
crazy idea for a generalized extractor object:
list.sorted(students, key=extract.score)
list.sorted(animal_weights, key=extract[1])
groupby(students, key=extract.homeroom)
groupby(recordtuples, key=extract[0])
Raymond Hettinger
P.S. The implementation code is very simple:
class ExtractorClass(object):
def __getattribute__(self, attr):
return operator.attrgetter(attr)
def __getitem__(self, key):
return operator.itemgetter(key)
extract = ExtractorClass()
More information about the Python-Dev
mailing list