searchLetter = str(input("Enter a Letter: ")
hulkLine= ["you", "wouldn't", "like", "me", "when", "i'm", "angry"]
def containsLetter(searchLetter, hulkLine):
for x in range(hulkLine -1):
if hulkLine[x] == 't':
我发布了以下函数的正确输出。
函数containsLetter()
有两个参数:
aLetter
strList
例如,以下是正确的输出:
>>> hulkLine = ["you", "wouldn't", "like", "me", "when", "i'm", "angry"]
>>> searchLetter = 'i'
>>> print(containsLetter(searchLetter, hulkLine))
>>> ["like", "i'm"]
答案 0 :(得分:2)
这可以吗?
>>> def containsLetter(searchLetter, hulkLine):
... return [x for x in hulkLine if searchLetter in x]
...
>>> containsLetter('i', hulkLine)
['like', "i'm"]
>>>
或
>>> filter(lambda x: searchLetter in x, hulkLine)
['like', "i'm"]
>>>