On 19 Feb 2014 07:26, "Paul Moore" <p.f.mo...@gmail.com> wrote: > > On 18 February 2014 21:17, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > > What I'd *really* like to be able to write is: > > > > sort(invoices, keyattr = 'duedate', none = 'first') > > Which is of course a pretty trivial utility function to write. But I > understand your point - these "trivial helpers" add up over time into > a bit of a burden. But fixing that (if anyone feels it's worth doing > so) can be handled many ways, and changing the semantics of None is > far from the simplest or most obvious.
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. 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. (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) Cheers, Nick. > > Pul > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com