dict.has_key(x) versus 'x in dict'

Fredrik Lundh fredrik at pythonware.com
Wed Dec 6 11:27:09 EST 2006


Roberto Bonvallet wrote:

>> this is why e.g.
>>
>>    string[:len(prefix)] == prefix
>>
>> is often a lot faster than
>>
>>    string.startswith(prefix)
> 
> This is interesting.  In which cases does the former form perform better?

no time to doublecheck right now, but iirc, last time we benchmarked 
this, slicing was faster when len(prefix) < 300 characters or so.

</F>




More information about the Python-list mailing list