Python 3では、文字列のリストと1つの文字列をパラメーターとしてfind(string_list, search)
受け取り、指定された検索文字列を含むすべての文字列のリストを返す関数を作成しようとしています。string_list
search
string_list
したがってprint(find(['she', 'sells', 'sea', 'shells', 'on', 'the', 'sea-shore'], 'he'))
、次のように出力します。
['she', 'shells', 'the']
これが私がこれまでに試したことです:
def find(string_list, search):
letters = set(search)
for word in string_list:
if letters & set(word):
return word
return (object in string_list) in search
ランニングprint(find(['she', 'sells', 'sea', 'shells', 'on', 'the', 'sea-shore'], 'he'))
私が期待したこと=[she, shells, the]
私が得たもの=[she]