On Sun, Dec 29, 2019 at 8:14 PM Andrew Barnert <abarn...@yahoo.com> wrote:
> On Dec 29, 2019, at 16:08, David Mertz <me...@gnosis.cx> wrote: > > > > * There is absolutely no need to lose any efficiency by making the > statistics functions more friendly. All we need is an optional parameter > whose spelling I've suggested as `on_nan` (but bikeshed freely). Under at > least one value of that parameter, we can keep EXACTLY the current > implementation, with all its warts and virtues as-is. Maybe a spelling for > that option could be 'unsafe' or 'fast'? > > This seems like the right way to go to me. > However, rather than coming up with appropriately-general implementations > of each of these things, wouldn’t taking a key function to pass through to > sorted be simpler for some? No, it wouldn't. That cannot deal with the 'raise' or 'poison' behaviors. Moreover, coming up with statistics.is_nan() and statistics.total_order() really isn't hard. Chris Barker already provided a pretty good is_nan() that we could use. In particular, coming up with a total_order function that works for all > valid number-like types is difficult; letting the user pass > key=math.total_order or decimal.Decimal.compare_total or > partial(decimal.Decimal.compare_total, context=my_context) or whatever is > appropriate is a lot simpler and a lot more flexible. Anyone who knows > that’s what they want should know how to pass it. > Here it is. I could save a line by not using the 'else'. def total_order(x): if is_nan(x): return (math.copysign(1, x)) else: return (0, x) Plus, finding the median_low or _high, with a key function actually seems > useful even without NaNs. “Find the median employee by salary” doesn’t seem > like a meaningless operation. > I'll give you that. That could be useful. However, I feel like that's too much for the module itself. It's easy to write it yourself with no function. median_employee = statistics.median((e.salary, e) for e in employees)[1] That's not so terribly much work for the user of the module. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at Code of Conduct: http://python.org/psf/codeofconduct/