On Mon, 8 Apr 2019 at 10:10, Steven D'Aprano <st...@pearwood.info> wrote:
> Possibly the maintainer of bisect may decide that its not worth the > change. But for the statistics module, I would certainly change the > implementation of median() to look something vaguely like this: > > # was > data = sorted(data) # may be expensive if data is large > > # may become > if not (isinstance(data, list) and data.__issorted__): > data = sorted(data) So just to be clear, this would be a change in behaviour - for a list that is currently sorted on a key that is *not* "numerically ascending", the code will no longer re-sort, and so will give the wrong answer? (Maybe the code is able to deal with either ascending or descending orders, I don't know about that, but even so, that just makes the failure rarer, not non-existent). I'm not saying that this is forbidden, just want to be clear if that's what you mean (because my difficulty with the proposed attribute is that it seems unreliable enough that I can't imagine a case where I'd feel comfortable using it myself). Paul PS I thought timsort was highly efficient given already sorted data? Whether it's OK to rely on that I don't know, but did you take that into account? _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/