Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-05 Thread Shiva
Larry Hudson yahoo.com.dmarc.invalid> writes: > > On 10/04/2014 10:36 AM, Shiva wrote: > > > > 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?? > > > > Very long

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread MRAB
On 2014-10-05 02:11, Denis McMahon wrote: On Sat, 04 Oct 2014 09:11:43 +, Shiva wrote: I have written a function that -reads a file -splits the words and stores it in a dictionary as word(key) and the total count of word in file (value). I want to print the words with top 20 occurrences in

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Denis McMahon
On Sat, 04 Oct 2014 09:11:43 +, Shiva wrote: > I have written a function that -reads a file -splits the words and > stores it in a dictionary as word(key) and the total count of word in > file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order - but

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Larry Hudson
On 10/04/2014 10:36 AM, Shiva wrote: 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?? Very long-winded explanation: (But to shorten it a bit, I'm going to use ts in place of t

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread MRAB
On 2014-10-04 18:36, Shiva wrote: > 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: > text

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Shiva
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 textsto

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Alexander Blinne
Am 04.10.2014 um 11:11 schrieb Shiva: > Hi All, > > I have written a function that > -reads a file > -splits the words and stores it in a dictionary as word(key) and the total > count of word in file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order -

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Peter Otten
Shiva wrote: > Hi All, > > I have written a function that > -reads a file > -splits the words and stores it in a dictionary as word(key) and the total > count of word in file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order - but can't figure it out.

Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Shiva
Hi All, I have written a function that -reads a file -splits the words and stores it in a dictionary as word(key) and the total count of word in file (value). I want to print the words with top 20 occurrences in the file in reverse order - but can't figure it out. Here is my function: def prin