← Back to context

Comment by gspetr

42 minutes ago

No, there's literally a "find" str method.

str.find(sub[, start[, end]])

"Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found."

Your instinct to resort to "in" is correct as it's generally slower than the "in" membership test, but the interviewer has even allowed the use of Google. Blanking out after that is really bad.