在单个文件中转换 Python 多个字典? [关闭]

问题描述 投票:0回答:0

假设我有一个清理字典文件的功能

def clean_result(data, buying_type):
    result = {}
    result['insights'] = {}
    
    result['data']['id'] = id
    result['data']['buying_type'] = buying_type
    
    return result


list1 = []
for item in data:
    res = clean_result(item, buying_type)
    list1.append(res)

它会返回我下面的列表

[{"id": "4362", "buying_type": "BID"},{"id": "4361", "buying_type": "BID"},{"id": "4363", "buying_type": "JOIN"}]

但是,我期望的结果是

{"id": "4362", "buying_type": "BID"}
{"id": "4361", "buying_type": "BID"}
{"id": "4363", "buying_type": "JOIN"}

然后存储在文件中。

如何得到我预期的结果?

python dictionary
© www.soinside.com 2019 - 2024. All rights reserved.