sorting dictionary keys?

Jay O'Connor joconnor at cybermesa.com
Sat Nov 29 18:03:56 EST 2003


Bruno Desthuilliers wrote:

> Jay O'Connor wrote:
>
>> John Smith wrote:
>>
>>  > Hi, what's the fastest way (least amount of typing)
>>
>> Never good criteria
>>
>>> but I would like to do:
>>> #error here
>>> for k in d.keys().sort():
>>>    print k, d[k]
>>>
>>> why doesn't the nested function call work?  Thanks in advance.
>>>
>>
>> sort() sorts in place and returns None
>>
>
> <rant>
> Which is one of the main PITA in Python IMHO :(
> (not the fact that it sort in place, the fact that it does not return 
> self).
> </rant> 


Arguably, if that's a main PITA, that's not too bad.  I like Python, but 
there are other things about it that bug me more.  It's a minor 
annoyance and given the name, I think it makes sense.  If it returned 
itself or a copy, the name should probably be sorted()





More information about the Python-list mailing list