copysort patch, was RE: [Python-Dev] inline sort option
Raymond Hettinger
python at rcn.com
Mon Oct 20 17:43:59 EDT 2003
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.
[Phillip J. Eby in a separate note]
> Wouldn't it need to grow key and cmpfunc, too?
Now, that "key" and "reverse" are available,
there is no need for "cmp" in any new methods.
[Guido in a separate note]
> list(range(10), reverse=True)
>
>would yield
>
> [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>
> But Raymond has a different proposal in mind for that (he still needs
to > > update PEP 322 though).
I'll get to it soon; there won't be any surprises.
Raymond Hettinger
#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################
More information about the Python-Dev
mailing list