[Python-ideas] Where should grouping() live (was: grouping / dict of lists)

Franklin? Lee leewangzhong+python at gmail.com
Mon Jul 9 23:30:25 EDT 2018


(Fixing quote and attribution.)

On Fri, Jul 6, 2018, 11:32 Chris Barker - NOAA Federal via
Python-ideas <python-ideas at python.org> wrote:
>
> On Jul 6, 2018, at 2:10 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> > On Fri, Jul 06, 2018 at 09:49:37AM +0100, Cammil Taank wrote:
> > > I would consider statistics
>
> > > to have similarities - median, mean etc are aggregate functions.
>
>
> Not really, more like reduce, actually -/ you get a single result.
>
> > > Histograms are also doing something similar to grouping.
>
> > .(Yes, a few statistics apply to nominal and ordinal data too,
>
>
> And for that, a generic grouping function could be used.
>
> In fact, allowing Counter to be used as the accumulater was one suggestion in this thread, and would build s histogram.
>
> Now that I think about it, you could write a key function that built a histogram for continuous data as well.
>
> Though that might be a bit klunky.
>
> But if someone thinks that’s a good idea, a PR for an example would be accepted:
>
> https://github.com/PythonCHB/grouper

+1 for `collections`, because it's where you look for something
similar to Counter.

-1 for `statistics`, because the need isn't specific to statistics.
It'd be like putting `commonprefix`, which is a general string
operation, into `os.path`. It's hacky to import a domain-specific
module to use one of its non-domain-specific helpers for a different
domain.

Someone can argue for functools, as that's the functional programming
module, containing `reduce`.


More information about the Python-ideas mailing list