How to get a directory list sorted by date?

Random832 random832 at fastmail.com
Mon May 16 12:40:07 EDT 2016


On Sun, May 15, 2016, at 17:52, Chris Angelico wrote:
> On Mon, May 16, 2016 at 2:00 AM, Grant Edwards
> <grant.b.edwards at gmail.com> wrote:
> > On 2016-05-15, Michael Selik <michael.selik at gmail.com> wrote:
> >> On Sun, May 15, 2016, 10:37 AM Grant Edwards <grant.b.edwards at gmail.com> wrote:
> >>> On 2016-05-15, Tim Chase <python.list at tim.thechases.com> wrote:
> >>>>
> >>>> unless sorted() returns a lazy sorter,
> >>>
> >>> What's a lazy sorter?
> >>
> >> One that doesn't calculate the next item in the sequence until you
> >> ask for it. It's impossible
> >
> > Why?  As long as the function has access to the entire sequence, it
> > should be trivial.  Just find the min (or max) item in the sequence,
> > remove it, then return it.  It's horribly inefficient, but...
> >
> >> unless you don't mind an approximation rather than correct sort.
> >
> > I have a feeling that I've missed the joke somewhere.
> 
> Sure, it's not impossible to implement, but generally the point of
> lazy generation is that it's more efficient. Going from O(N log N)
> with O(N) memory to O(N*N) with O(1) memory is not usually what you
> want!

It could be "lazy" in the sense that it doesn't consume the source
iterator or do any sorting at all until you start iterating it. And if
you perform some operation (such as, for example, sorting again by a
different key) that is destructive of the original order it could
dispense with the sorting process (or compose the two key functions, if
the sorting algorithm is meant to be stable)

Or, for example, if you filter the sorted collection, a "lazy"
filter/sorter could reorder the operations so that the unsorted list is
filtered before being sorted, reducing N for the sort operation.



More information about the Python-list mailing list