python - 如何解决 AttributeError:'list' 对象在 python 中没有属性'keys'
问题描述
if w in data:
return data[w]
# for getting close matches of word
elif len(get_close_matches(w, data.keys())) > 0:
yn = input("Did you mean % s instead? Enter Y if yes, or N if no: " % get_close_matches(w, data.keys())[0])
yn = yn.lower()
if yn == "y":
return data[get_close_matches(w, data.keys())[0]]
elif yn == "n":
return "The word doesn't exist. Please double check it."
else:
return "We didn't understand your entry."
else:
return "The word doesn't exist. Please double check it."
解决方案
data
代码中的对象不是字典。这是一个列表,列表没有键。您需要将data
对象实现为字典。
推荐阅读
- c# - C#我将如何编写一个实用程序来更新不同文件夹中多个配置文件的 IP 地址
- html - 侧边栏渐变从左到右但也向下
- objective-c - 将通知(NSNotification)作为另一个通知的用户信息传递是否安全?
- python - 根据 Matplotlib 中的值填充水平条形图矩形
- c# - MSOrleans 2.0 Ado.net 持久版
- sql - LEFT JOIN 时缺少一张表中的数据
- ios - 丰富的推送通知在 iOS 的 iPhone 11 Pro Max 中不起作用
- angular - Angular 8 授权指令仅在第一次工作
- html - 导航不可选择
- android - 在 bazel 中添加 sceneform(arcore) 依赖项