"Newbie" questions - "unique" sorting ?
Bryan
belred1 at yahoo.com
Wed Jun 25 21:54:03 EDT 2003
i just did a test comparing:
if key not in mydict:
and
if not mydict.has_key(key):
and the 1st way cameout 28% faster. (on python 2.3)
bryan
"Erik Max Francis" <max at alcyone.com> wrote in message
news:3EFA2521.94B42B9B at alcyone.com...
> 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