Dictionary sorting problem

JerryB grblanco at gmail.com
Fri Sep 16 15:31:46 EDT 2005


Hi,
I have a dictionary for counting ocurrences of strings in a document.
The dictionary looks like this:

'hello':135
'goodbye':30
'lucy':4
'sky':55
'diamonds':239843
'yesterday':4

I want to print the dictionary so I see most common words first:

'diamonds':239843
'hello':135
'sky':55
'goodbye':30
'lucy':4
'yesterday':4

How do I do this? Notice I can't 'swap' the dictionary (making keys
values and values keys) and sort because I have values like lucy &
yesterday which have the same number of occurrences.

Thanks.




More information about the Python-list mailing list