On 4/8/19 6:25 AM, Steven D'Aprano wrote:
> On Mon, Apr 08, 2019 at 02:55:54AM -0700, Nathaniel Smith wrote:

>> If only we had some kind of API that could compute multiple quantiles at
>> the same time...
>
> You mean something like this?
>
> quartiles, quintiles, deciles, percentiles = quantiles(data, n=(4, 5, 10, 100))
>
> Yuck :-)
>
> I'd rather allow an already_sorted=True parameter :-)

I'd rather have a separate function.  I can't think of a good name for
it right now, but it'd be just like quantiles, except that you'd pass it
a sorted list.  Conceptually, it'd fit in like this:

    def quantiles(data, n):
        if isinstance(data, list): # or some other appropriate test
            sorted_data = sorted(data)
        else:
            sorted_data = data
        quantiles_of_sorted_data(sorted_data, n)

    def quantiles_of_sorted_data(sorted_data, n):
        ...actual quantiles functionality here...

Properly constructed programs that would have called quantiles
repeatedly can call quantiles_of_sorted_data repeatedly instead.  The
ability to shoot a foot remains unchanged.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to