"Newbie" questions - "unique" sorting ?

Erik Max Francis max at alcyone.com
Wed Jun 25 18:41:37 EDT 2003


Cousin Stanley wrote:

> I changed one line in the script ....
> 
>     from .... if this_word not in dict_words.keys()  :
> 
>     to ...... if not dict_words.has_key( this_word ) :
	...
> I failed to consider here
> that a  NEW  keys list might be created
> on each pass through a loop ....

Not only does it create a new keys list (D.keys()), but it searches
linearly through it (x in L)!  Those are two separate O(n) operations,
whereas D.has_key is effectively O(1).

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ The multitude of books is making us ignorant.
\__/  Voltaire




More information about the Python-list mailing list