なぜ空リストを取得するのか分かりませんが、この関数をテストします。誰でもこの問題を解決するのを助けてくれますか?キーワードが関連付けられたファイル名のリストを返します
def find_images_with_keyword(key_dict, keywords_list):
'''(dict of {str: list of str}, list of str) -> list
Given a keyword_dictionary and a list of keywords,
return the list of filenames associated with the given keywords.
The list of filenames should include all filenames having one or more
of the specified keywords(ie, a filename may be associated with only one,
not all of the keywords in the list).
>>> find_images_with_keyword({'dog': ['1.png', '2.png'], 'animal': ['1.png', '3.png']}, ['dog', 'animal'])
['1.png', '2.png', '3.png']
'''
new_list = []
for keyword in key_dict.items():
for filename in keywords_list:
if keyword == filename:
new_list.append(filename)
return new_list
現在のアイテムの名前として 'keyword'を使用する2つの' for'ループがあります。それらのうちの1つが 'filename'であると仮定していますか?そうでなければ、その変数が – UnholySheep
であるはずなのかどうかは不明です。質問を整理できますか?入力は何ですか、期待される出力は何ですか? –
'filename'は定義されていません。 –