在不同的字符串中找到一个 'hello' 单词,其中包含 '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']


跃然一笑
浏览 165回答 1
1回答

心有法竹

这是我认为可以在字符串中找到“hello”字的代码。firststring = input() #ahhellllloouto_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))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python