Assume all letters in the given words are lowercase. You may use string methods if any are useful.
>>> occurs_within('aaacaabxyt', 'cat')
True
>>> occurs_within('tac', 'cat')
False
>>> occurs_within('oboe', 'bob')
False
>>> occurs_within('ecxbtalt', 'exalt')
True
>>> occurs_within('ecxbtal', 'exalt')
False
if len(word1) > len(word2):
for i in range(0,len(word1)):
if word2[i] < word2[i+1]:
return True
else:
return False
else:
return False
I tried using a nested for loop inside an if function comparing the two strings and looping to find if the next index of string 2 that is with in string 1 is greater than that of the previous index, but it turns out my result are all True somehow, and I cant figure out what seem to be the problem.