Anthony Liu wrote:
mydict = {'the':358, 'they':29, 'went':7, 'said':65}
Is there an easy to sort this dictionary and get a
list like the following (in decreasing order)?
Yes.

    def sortkey((word, frequency)):
        return -frequency, word

    for word_freq in sorted(mydict.items(), key=sortkey):
        print '%-6s %s' % word_freq


--Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Reply via email to