copysort patch, was RE: [Python-Dev] inline sort option

Raymond Hettinger python at rcn.com
Wed Oct 22 14:30:53 EDT 2003


Did the discussion of a sort() expression get resolved?

The last I remember was that the list.sorted() classmethod had won the
most support because it accepted the broadest range of inputs.

I could live with that though I still prefer the more limited
(list-only) copysort() method.



Raymond Hettinger


> Let's see what the use cases look like under the various proposals:
> 
>   todo = [t for t in tasks.copysort() if due_today(t)]
>   todo = [t for t in list.sorted(tasks) if due_today(t)]
>   todo = [t for t in list(tasks, sorted=True) if due_today(t)]
> 
>   genhistory(date, events.copysort(key=incidenttime))
>   genhistory(date, list.sorted(events, key=incidenttime))
>   genhistory(date, list(events, sorted=True, key=incidenttime))
> 
>   for f in os.listdir().copysort(): . . .
>   for f in list.sorted(os.listdir()): . . .
>   for f in list(os.listdir(), sorted=True): . . .
> 
> To my eye, the first form reads much better in every case.
> It still needs a better name though.




More information about the Python-Dev mailing list