<p dir="ltr"><br>
On 19 Feb 2014 07:26, "Paul Moore" <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>> wrote:<br>
><br>
> On 18 February 2014 21:17, Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>> wrote:<br>
> > What I'd *really* like to be able to write is:<br>
> ><br>
> >    sort(invoices, keyattr = 'duedate', none = 'first')<br>
><br>
> Which is of course a pretty trivial utility function to write. But I<br>
> understand your point - these "trivial helpers" add up over time into<br>
> a bit of a burden. But fixing that (if anyone feels it's worth doing<br>
> so) can be handled many ways, and changing the semantics of None is<br>
> far from the simplest or most obvious.</p>
<p dir="ltr">So perhaps the real answer is for someone to write a sorting helper module and put it on PyPI. Things like sort_byattr (implicitly uses attrgetter), sort_byitem (implicitly uses itemgetter), a flag argument defaulting to "none_first=True", SortsLow and SortsHigh singletons, etc.</p>

<p dir="ltr">Those don't need to be builtins, but collating them into a clean helper API would not only allow that module to be used directly, but also act as a reference for anyone wanting to implement the behaviour themselves.</p>

<p dir="ltr">(I know, I know, we're way into python-ideas territory - it's just that so much if the thread *was* on topic for python-dev, it seems relatively pointless to split this iteration of the discussion. The *next* thread about it should definitely be on python-ideas, though)</p>

<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> Pul<br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>