Issue in printing top 20 dictionary items by dictionary value

Shiva shivaji_tn at yahoo.com
Sat Oct 4 13:36:52 EDT 2014


It works :
orderedwords = sorted(textstorage.keys(), key=textstorage.get)

The method textstorage.get will accept a word and return it's value which in
this instance is the count.

What I don't understand is:

    for w in eachword:
        textstorage[w]=textstorage.get(w, 0) + 1

How does textstorage.get(w,0)+1 give the count of the word??

Thanks,
Shiva




More information about the Python-list mailing list