"Newbie" questions - "unique" sorting ?

Bryan belred1 at yahoo.com
Wed Jun 25 04:34:03 CEST 2003


> 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
> >
>
>


this is how i check if a key is in a dictionary:

if this_word not in dict_words:

i believe this doesn't do an O(n) search over it.  it's supposed to constant
time for every lookup by way of a hash lookup.

bryan






More information about the Python-list mailing list