【发布时间】:2020-10-03 23:57:16
【问题描述】:
我正在寻找在嵌套字典中创建一个字典,其中键是 store,值是 store_type。我希望它输出带有 store 的键和值的字典:store_type。
我已经尝试过,但无法让 store 和 store_type 在没有出现类型或属性错误的情况下返回:
def get_store(large_dict):
for i in large_dict:
name = i["store"]
party = i["store_type"]
下面的示例代码
"parent": 116,
"child": 2,
"group": "member",
"bucket_number": 130,
"source": "https://www.webiste.com/",
"url": "hhttps://www.website.com/",
"preference": {},
},
{
"order": 3241235,
"store": "Target",
"description": "Expect More, Pay Less",
},
"previous_orders": [
{
"order_id": "0213124",
"store": "Target",
"store_type": "Retail",
"state": "AL",
},
{
"order_id": "0213125",
"store": "Publix",
"store_type": "Grocery",
"state": "AL",
},
{
"order_id": "0213126",
"store": "Winn-Dixie",
"store_type": "Grocery",
"state": "AL",
},
{
"order_id": "0213127",
"store": "Sur la Table",
"store_type": "Retail",
"state": "AL",
},
{
"order_id": "0213128",
"store": "Trader Joes",
"store_type": "Grocery",
"state": "AL",
}
【问题讨论】:
-
显示你的回溯
标签: python python-3.x dictionary