python-为什么我的代码没有附加所有电影?
发布时间:2022-07-24 05:45:08 277
相关标签: # node.js
我必须为学校做一个练习,但我做不到。任务如下:
定义函数;x“;这需要一个像上一个一样的目录和一个最喜欢的主题列表,并为涉及任何这些主题的电影生成建议。
目录如下:
example = [
{"title": "The Hard Way", "themes": ["Action & Adventure"]},
{"title": "Asmaa", "themes": ["Dramas", "International Movies"]},
{"title": "Dukhtar", "themes": ["Dramas", "Independent Movies", "International Movies"]},
{"title": "The Bachelorette", "themes": ["Reality TV", "Romantic TV Shows"]},
{"title": "12 Years Promise", "themes": ["International TV Shows", "Korean TV Shows", "Romantic TV Shows"]},
{"title": "Alexandria: Again and Forever", "themes": ["Classic Movies", "Dramas", "International Movies"]},
{"title": "Road Trip: Beer Pong", "themes": ["Comedies"]},
{"title": "Chashme Buddoor", "themes": ["Comedies", "International Movies", "Music & Musicals"]},
{"title": "House Party 3", "themes": ["Comedies", "Music & Musicals"]},
{"title": "Manhunt", "themes": ["Action & Adventure", "International Movies"]}
]
这是我到目前为止编写的代码:
def x(catalog,list):
recomended = []
for element in catalog:
if list[0] in element["themes"]:
list.append(recomended, element["title"])
return recomended
它返回 ['Asmaa', 'Dukhtar', 'Alexandria: Again and Forever'],但它应该返回 ["Asmaa", "Dukhtar", "12 Years Promise", "Alexandria: Again and Forever"]。
我相信问题是因为我只检查主题中的第一个元素,但我不知道如何检查主题中的所有元素。
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报