[Python-ideas] __sort__ special member
Oleg Broytman
phd at phdru.name
Fri Jul 20 18:23:11 CEST 2012
On Fri, Jul 20, 2012 at 06:11:52PM +0200, David Townshend <aquavitae69 at gmail.com> wrote:
> I was quite surprised to find that nobody seems to have suggested this
> before, because it seems like an obvious idea. Basically, add a special
> method __sort__ which, if specified, is used when sorted() is called. I can
> think of two immediate use cases:
>
> 1. When an object wants sorted() to return something other than a list,
> e.g. dict.__sort__ could return an OrderedDict.
> 2. When there is a more efficient method of sorting a specific sequence.
> E.g. sorting a range object should be trivial.
>
> Is there some obvious reason why nobody has suggested this before? Is it
> worth pursuing?
Because it's too application-specific?
Oleg.
--
Oleg Broytman http://phdru.name/ phd at phdru.name
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-ideas
mailing list