我是Python的新手,正在努力学习编写快速代码的最佳方法。我正在处理一个包含嵌套字典的练习,这是我正在使用的字典:
{
"key_1": [
{
"title": <title>,
"date": <date>,
"text": <text>
}
],
"key_2": [
{
"title": <title>,
"date": <date>,
"text": <text>
}
],
"key_3": [
{
"title": <title>,
"date": <date>,
"text": <text>
}
]
}
这是我编写的代码来访问它。但由于我有三个嵌套的for循环,我认为这不够快:
for main_key, main_value in dictionary.items():
if main_value:
for value in main_value:
for sub_keys, sub_values in value.items():
if sub_keys == "date":
print(sub_values)
有没有关于如何让我的代码更加简洁和快速的指南?非常感谢提前帮助!