我应该在字符串中找到一个“ hello”单词,该单词是我从输入中给出的。 这是我当前拥有的代码,但是我无法将'hello'与字符列表匹配。
mylist = 'it can be any letter plus hello in it'
for letter in mylist:
if letter in key:
mylist2+=letter
print(mylist2)
mylist2 = ['h', 'h', 'e', 'l', 'l', 'l', 'l', 'l', 'o', 'o']
答案 0 :(得分:0)
这是我认为可以在字符串中找到“ hello”单词的代码。
firststring = input() #ahhellllloou
to_find = "hello"
def check_string(firststring, to_find):
c = 0
for i in firststring:
#print(i)
if i == to_find[c]:
c += 1
if c == len(to_find):
return "YES"
return "NO"
print(check_string(firststring, to_find))