Way for see if dict has a key

Bruno Desthuilliers onurb at xiludom.gro
Fri Jun 30 11:17:48 EDT 2006


Fredrik Lundh wrote:
> Bruno Desthuilliers wrote:
> 
>>> on my machine, "key in dict" is about twice as fast as the full
> 
>>> try/getitem construct when the key is present in the dict,
> 
>>
>> Doesn't it depends on the number of keys in the dict ?
> 
> 
> why would it depend on the number of keys in the dict ?
> 
> </F>

Seems that if "key in dict" do a simple linear search, it depends on the
number of keys in dict (and the position of the searched key etc...).

And if I'm missing the point and you it and you know why, it would be
simple to explain than to answer my question with another question.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list