I'm trying to write a simple function in python to do what in or str.contains does, here are the codes:
def contains(big, little):
length = len(little_string)
for i in big:
if big[i:i+length-1] == little:
return True
return False
For line if big[i:i+length-1] == little:`` it throws a TypeError saying must be str not int and I'm baffled. Since I think as long as big is a string the slicing of it will certainly be string too.
Does anyone know why this happened? thanks a lot.
bigis astr, thenfor i in bigwill yield characters of the stringfor i in len(big).for i in range(len(big)).