"Newbie" questions - "unique" sorting ?
Kim Petersen
kp at kyborg.dk
Tue Jun 24 05:16:47 EDT 2003
Cousin Stanley wrote:
> | How about the simple approach?
> | ...
>
> Kim ...
>
> The approach I used is fairly simple and similar
> to the one you posted, basically just
> stuffing words from split lines into
> a dictionary ...
yeah it is - a reminder to me not to do any scanning of code before my
morning coffee ;-)
> Perhaps skipping the dictionary word count update
> in the following line might speed things up ...
totally skipping the word count should speed it up - and i believe that
the approach of dict_words[this_word]=dict_words.get(this_word,0) btw.
is a bit faster than doing has_key() or the least of doing:
if this_word not in dict_words.keys() :
which aught to be extremely slow on a large dictionary (creating and
dropping lists of thousands + doing a O(n) search over it). And that may
very well be the culprit of the slow run you see....
>
> else :
>
> dict_words[ this_word ] += 1
>
--
Med Venlig Hilsen / Regards
Kim Petersen - Kyborg A/S (Udvikling)
IT - Innovationshuset
Havneparken 2
7100 Vejle
Tlf. +4576408183 || Fax. +4576408188
More information about the Python-list
mailing list