How to get a directory list sorted by date?

Tim Chase python.list at tim.thechases.com
Sun May 15 14:12:32 EDT 2016


On 2016-05-15 14:36, Grant Edwards 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?

A hypothetical algorithm that can spool out a sorted sequence without
holding the entire sequence in memory at the same time. 

Though I typed that initial reply a little quickly, as I hadn't known
at the time that scandir()'s results also provide stat() results with
reduced overhead (whereas listdir() just returns the filenames, so
you have to stat() each one).  Thanks, Peter, for highlighting this
feature.

So in light of my newfound knowledge, I humbly retract my snark and
agree that it's better to exploit scandir()'s inclusion of stat()
details without additional calls.

-tkc







More information about the Python-list mailing list