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

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Oct 21 19:53:01 EDT 2003


> From: Greg Ewing [mailto:greg at cosc.canterbury.ac.nz]
> 
> Maybe dicts should have a .sortedkeys() method? The specialised
> method name would help stave off any temptation to add varied sort
> methods to other types.

-1.

I think that:

    d = {1: 2, 3: 4}

    for i in list.sorted(d):
        print i

or

    d = {1: 2, 3: 4}

    for i in list.sorted(d.iterkeys()):
        print i

looks very clean and unambiguous. And is even better at staving off temptation to add varied sort methods to other types.

Tim Delaney



More information about the Python-Dev mailing list