[Python-ideas] Multiple level sorting in python where the order of some levels may or may not be reversed

Sven R. Kunze srkunze at mail.de
Mon Oct 17 16:06:22 EDT 2016


On 16.10.2016 09:35, Alireza Rafiei wrote:
> Awesome! Thanks for the thorough explanation.

Indeed. I also didn't know about that detail of reversing. :) Amazing. 
(Also welcome to the list, Alireza.)

>
>         def multisort(xs, specs):
>             for key, reverse in reversed(specs):
>                 xs.sort(key=key, reverse=reverse)
>
>     That's all it takes!  And it accepts any number of items in `specs`.
>     Before you worry that it's "too slow", time it on real test data.
>     `.sort()` is pretty zippy, and this simple approach allows using
>     simple key functions.  More importantly, it's much easier on your
>     brain ;-)
>
>

@Tim
Do you think that simple solution could have a chance to be added to 
stdlib somehow (with the possibility of speeding it up in the future)?


Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161017/45c9c30f/attachment.html>


More information about the Python-ideas mailing list