I'm just glancing at this thread, but it sounds like you want to add the quickselect algorithm to the standard library. As you point out in another message, quickselect is faster than quicksort: it is linear time (provided the pivot is chosen by median of medians) whereas quicksort is expected linearithmic time.
Using quickselect, you could select any order statistic: the median, the 25th percentile, etc. If it were added, I guess it probably belongs in statistics. Best, Neil On Thursday, December 26, 2019 at 3:14:33 PM UTC-5, David Mertz wrote: > > Maybe we can just change the function signature: > > statistics.median(it, do_wrong_ass_thing_with_nans=False) > > :-) > > But yes, the problem is really with sorted(). However, the implementation > of statistics.median() doesn't HAVE TO use sorted(), that's just one > convenient way to do it. > > There IS NO right answer for `sorted([nan, 1, 2, 3])`. However, there is > a very plausibly right answer for `statistics.median([nan, 1, 2, 3])` ... > or rather, both 'nan' and '2' are plausible (one approach is what Numpy > does, the other is what Pandas does). > > -- > 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 https://mail.python.org/archives/list/python-ideas@python.org/message/FE2A6LAFA4ETV3JEZ5VFHGGPEV5LSA6G/ Code of Conduct: http://python.org/psf/codeofconduct/