itertools.groupby

Tobiah toby at tobiah.org
Tue Jan 15 15:28:38 EST 2008


In the docs and examples that I have seen so far,
it is suggested that the groupby() input list may be pre-sorted
with the same function that is passed to groupby as
a key extractor.

I tried doing this with a simple example, but noticed
that [].sort(func) passes two arguments to func, whereas
the function expected by groupby() uses only one argument.

It would seem that two differently written functions would
have to be created which operate on the data in conceptually
similar but practically different ways in order to presort
the input list so that semantically similar items all make
it into the same group.

Thanks,

Toby

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list