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

Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Dave Angel
I expect is "one call with criteria 'Test' and one with 'Running'. From my logs file, the duplicate call always occurs at the last iteration of the dictionary items. Do you mean there are 3 calls to that method, with only two items in the dictionary?? More likely, there&

Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Ombongi Moraa Fe
t' and one with 'Running'. From my logs file, the duplicate call always occurs at the last iteration of the dictionary items. In short, my problem arises after I include the if statement inside the loop. I am new to python but I am pretty sure my program syntax is correct here. If I

Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Dave Angel
On 04/15/2013 06:50 AM, Ombongi Moraa Fe wrote: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): .

RE: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Peter Otten
Ombongi Moraa Fe wrote: > hello Team, > > I have this fairly simple script to iterate the dictionary items and check > if the items match certain values; > > dictionary={'1234567890':001, '0987654321':002} > for k, v in dictionary.iteritems(): >

Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Mark Lawrence
On 15/04/2013 11:50, Ombongi Moraa Fe wrote: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): .

RE: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Ombongi Moraa Fe
hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): . . #suds client statements; if (k =

Re: Dictionary : items()

2009-01-22 Thread Benjamin
On Jan 22, 2:53 am, Paul Rubin wrote: > Steven D'Aprano writes: > > That is better written as: > > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) > > In Python 2.x, I prefer the style > >   l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) >

Re: Dictionary : items()

2009-01-22 Thread Paul Rubin
Steven D'Aprano writes: > That is better written as: > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) In Python 2.x, I prefer the style l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) but Python 3.0 breaks the tuple unpacking per some PEP. -- http://mail.python.org

Re: Dictionary : items()

2009-01-22 Thread Steven D'Aprano
On Wed, 21 Jan 2009 23:02:11 -0800, koranthala wrote: > Hi, >Dictionary has the items method which returns the value as a list > of tuples. >I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. >

Re: Dictionary : items()

2009-01-21 Thread Terry Reedy
koranthala wrote: Hi, Dictionary has the items method which returns the value as a list of tuples. I was wondering whether it would be a good idea to have an extra parameter - sort - to allow the tuples to be sorted as the desire of users. Currently what I do is: class SDict(dict):

Dictionary : items()

2009-01-21 Thread koranthala
Hi, Dictionary has the items method which returns the value as a list of tuples. I was wondering whether it would be a good idea to have an extra parameter - sort - to allow the tuples to be sorted as the desire of users. Currently what I do is: class SDict(dict): def items(self, sort