【发布时间】:2020-02-14 21:00:56
【问题描述】:
假设给定单词中的所有字母都是小写的。 如果有用的话,你可以使用字符串方法。
>>> 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
我尝试在 if 函数中使用嵌套 for 循环比较两个字符串并循环查找字符串 1 中的字符串 2 的下一个索引是否大于前一个索引的索引,但结果是我的结果不知何故都是真实的,我无法弄清楚似乎是什么问题。
【问题讨论】: