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

Roberto Bonvallet Roberto.Bonvallet at cern.ch
Wed Dec 6 10:12:35 EST 2006


Fredrik Lundh 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?
[I won't stop using str.startswith anyway :) ]

Regards.
-- 
Roberto Bonvallet



More information about the Python-list mailing list