Re: [Tutor] Simple counter to determine frequencies of words in adocument

2010-11-21 Thread Alan Gauld
"Josep M. Fontana" wrote : return sorted( : word_table.items(), key=lambda item: item[1], reverse=True : ) By the way, I know what a lambda function is and I read about the key parameter in sorted() but I don't understand very well what "key=lambda item: item[1]" does. ... What I don

Re: [Tutor] Simple counter to determine frequencies of words in adocument

2010-11-20 Thread Alan Gauld
"col speed" wrote Just my twopenneth, I'm a noob and I'm not going to try such a big file on my old machine, but: 1. Maybe create a *set* from the wordlist, loop through that, so you call "count" on wordlist only once. OR This would be an improvement but still involves traversing the en

Re: [Tutor] Simple counter to determine frequencies of words in adocument

2010-11-20 Thread Peter Otten
Alan Gauld wrote: > The loop is a bit clunky. it would be clearer just to iterate over > a_list: > > for item in a_list: >words[item] = a_list.count(item) This is a very inefficient approach because you repeat counting the number of occurrences of a word that appears N times N times: >>> w

Re: [Tutor] Simple counter to determine frequencies of words in adocument

2010-11-20 Thread Alan Gauld
"Josep M. Fontana" wrote The code I started writing to achieve this result can be seen below. You will see that first I'm trying to create a dictionary that contains the word as the key with the frequency as its value. Later on I will transform the dictionary into a text file with the desire