lst=[{'rating':[9.7,2062397],'id':'1292052','type':['犯罪','剧情'],'title':'肖申克的救赎','actors':['蒂姆·罗宾斯','摩根·弗里曼']}, {'rating':[9.6,1528760],'id':'1291546','type':['剧情','爱情','同性'],'title':'霸王别姬','actors':['张国荣' ,'张丰毅' , '巩俐' ,'葛优']}, {'rating':[9.5,1559181],'id':'1292720','type':['剧情','爱情'],'title':'阿甘正传','actors':['汤姆·汉克斯','罗宾·怀特 ']} ] name = input('请输入你要查询的演员:') for i in lst:#得到一个个字典 lst1 = i['actors'] #得到字典的值,字典的值刚好为列表,无需转换为列表 for actor in lst1: #遍历演员名字 if name in actor: print(name+'演出了'+i['title'])
E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonProject/demon1/demo34.py 请输入你要查询的演员:张国荣 张国荣演出了霸王别姬 进程已结束,退出代码0
标签:rating,部题,title,11.4,思路不清,actors,张国荣,type,id From: https://www.cnblogs.com/988MQ/p/16667336.html