help printing dictionary, sorted by values.

Jerry Williams jwilliam at xmission.com
Tue Aug 17 01:16:47 EDT 1999


I have searched and searched the docs and am really frustrated with
them.
All I can seem to find is bits and pieces that hint about dictionaries.
I finally found a table under mappings that listed the methods.  But
I couldn't find anything that would list each data type and what methods
are available.  What I am trying to do is take a file with a bunch of
entries that appear more than once and list the count of each occurance
in order of the highest count.  So if the file looked like:
a
a
a
b
b
c
Then is would print:
3 a
2 b
1 c
I thought a dictionary would work great, but can't seem to figure out
how to sort it by values and also get the key.
list = dict.values()
list.sort()
Then I get lost.  And the counts aren't going to be unique.
Thanks for any help.  Please point me to where the methods are listed
for
the dictionary.  And some examples of dictionaries would be helpful.




More information about the Python-list mailing list