Sorting a dictionary
toby at tobiah.org
Fri May 15 12:57:56 EDT 2009
On Tue, 12 May 2009 14:17:54 +0200, Jaime Fernandez del Rio wrote:
> This one I think I know... Try with:
> for k in sorted(word_count) :
> print k,"=",word_count[k]
> You need to do the sorting before iterating over the keys...
Isn't that what's happening here? I read this as the
'sorted' function iterating over the keys in word_count,
then passing that sorted list to the 'for' loop, for a
second iteration over the sorted pairs.
More information about the Python-list