[Python-Dev] dict.sortedkeys()

Robert Brewer fumanchu at amor.org
Sat Apr 17 16:21:26 EDT 2004


[Jeff Epler]
> Factor sorted into a function that returns a sorted copy:
>     def sorted(seq):
>         seq = list(seq)
>         seq.sort()
>         return seq
> 
> or one that sorts in place:
>     def sorted(seq):
>         seq.sort()
>         return seq
> 
> Now you can write your one-liner:
> for i in sorted({}.keys()):
>     ...

Yes, of course. But I'm working on a large business app framework. That
means either:

1. Writing sorted into every module where it's needed.
2. Putting sorted into a package somewhere, which makes it longer and
uglier with absolute referencing.
3. Customizing consumers' Python install.

...none of which are good options.


[Bob Ippolito]
> I'm pretty sure that in Python 2.4 you will be able to say
sorted(seq).

Excellent! That'll do nicely. :)


-another bob



More information about the Python-Dev mailing list