【发布时间】:2020-05-26 04:27:26
【问题描述】:
我是这个网站的新手,所以对我温柔一点,不是同性恋。
我目前正在使用代码来练习我的 Python 技能,该代码会根据 JSON 字典检查给定的键并为您提供键的定义。 现在我知道我的问题还有其他解决方案,但如果可能的话,我正在尝试专门解决这个问题。
我正在尝试将字典中的所有键更改为小写,我现在正在尝试这样:
data = json.load(open("data.json"))
for key in data.keys():
key = key.lower()
这个字典文件是什么样子的(一键示例):
"act": ["Something done voluntarily by a person, and of such a nature that certain legal consequences attach to it.", "Legal documents, decrees, edicts, laws, judgments, etc.", "To do something.", "To perform a theatrical role."]
显然,每个键都有一个以上的值,这在尝试其他解决方案时会产生问题。
【问题讨论】:
-
key = key.lower()只是将新的小写str对象分配给局部变量key。
标签: python json dictionary lowercase