"Ordered" dicts

Scott David Daniels Scott.Daniels at Acm.Org
Wed Aug 10 11:43:25 EDT 2005


Simon Brunning wrote:
> On 8/10/05, Chris Cioffi <evenprimes at gmail.com> wrote:
> 
>>I have lots of code that looks like: 
>>    keys = mydict.keys() 
>>    keys.sort() 
> 
> 
> keys = sorted(mydict.keys())
> 
Or (often useful to get at contents):

    items = sorted(mydict.items())

as in:

     For key, value in sorted(mydict.items()):
         print '%s -> %r' % (key, value)

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list