[Python-Dev] Other library code transformations

Tim Peters tim.one@comcast.net
Fri, 31 May 2002 13:04:08 -0400

]Raymond Hettinger]
>> if item in astring --> if item in adict

> Huh?  What does this mean?

I assume the only point is speed.  Provided there are no collisions, "in" on
a character-keyed dict acting as a set is faster than "in" applied to a
string, even if the character searched for is the first character in the
target string.  But it's only a little faster then today.  It's about 50%
faster by the time you have to search ~= 50 characters into a string before
finding a hit.  However, most uses of "character in string" have very short
"string" parts (like "ch in '/\\'"), and I don't judge the minor speed gain
there worth the extra bother and obscurity of maintaining a static set