如何解决 AttributeError:'list' 对象在 python 中没有属性'keys' [关闭]
Posted
技术标签:
【中文标题】如何解决 AttributeError:\'list\' 对象在 python 中没有属性\'keys\' [关闭]【英文标题】:How to slove AttributeError: 'list' object has no attribute 'keys' in python [closed]如何解决 AttributeError:'list' 对象在 python 中没有属性'keys' [关闭] 【发布时间】:2021-11-08 03:30:39 【问题描述】: 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."
【问题讨论】:
【参考方案1】:data
代码中的对象不是字典。这是一个列表,列表没有键。您需要将data
对象实现为字典。
Difference between List and Dictionary in Python
【讨论】:
以上是关于如何解决 AttributeError:'list' 对象在 python 中没有属性'keys' [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
AttributeError: 'list' object has no attribute 'sorted'
Selenium 之 报错AttributeError: 'list' object has no attribute 'click'
初学者 Python:AttributeError:'list' 对象没有属性
AttributeError:'list' 对象没有属性 'size'