问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
'''
1.将下列鸡尾酒的数据保存为字典数据,并回答下列问题
(1)哪些鸡尾酒含有伏特加?
(2)那些鸡尾酒是含有伏特加,但是不含有乳糖或者苦艾酒的?
'''
mydisc = {"马提尼":["伏特加","苦艾酒"],"黑俄罗斯":["伏特加","咖啡酒"],"白俄罗斯":["乳糖","咖啡酒","伏特加"],"曼哈顿":["黑麦威士忌","苦艾酒","比特酒"],"螺丝起子":["橙汁","伏特加"]}
a = list(mydisc.values())
for i in a:
#i = 0,i=1,i=2,i=3,i=4
if "伏特加" in a[i]:
b = list(mydisc.keys())[list(mydisc.values()).index(a[i])]
print(b)
运行结果及报错内容
Traceback (most recent call last):
File "E:\pythonProject\venv\test9.py", line 6, in
if "伏特加" in a[i]:
TypeError: list indices must be integers or slices, not list
我的解答思路和尝试过的方法
我想要达到的结果
遍历a[i]