Python 3.x 如何在python中将我的sql结果转换为以下字典格式?
我有这样一个示例结果:Python 3.x 如何在python中将我的sql结果转换为以下字典格式?,python-3.x,dictionary,Python 3.x,Dictionary,我有这样一个示例结果: [{'BUSINESS_UNIT': 'Communications', 'PROCESS': 'Contributions', 'GEO': 'Europe', 'MARKET': 'Global', 'COUNTRY': 'France', 'RPTG_QTR': '2018 Q3'}, {'BUSINESS_UNIT': 'Communications', 'PROCESS': 'Contributions', 'GEO': 'Glob
[{'BUSINESS_UNIT': 'Communications',
'PROCESS': 'Contributions',
'GEO': 'Europe',
'MARKET': 'Global',
'COUNTRY': 'France',
'RPTG_QTR': '2018 Q3'},
{'BUSINESS_UNIT': 'Communications',
'PROCESS': 'Contributions',
'GEO': 'Global',
'MARKET': 'Global',
'COUNTRY': 'France',
'RPTG_QTR': '2018 Q4'}]
我尝试了几种方法,比如使用defaultdict,但仍然没有效果
for row in surveys: #Format the results
result = {'BU':{row['BUSINESS_UNIT']:{'Process':{row['PROCESS']:'GEO'}}}}
#print(row['PROCESS'])
#print(row)
print(type(result))
result
我想将其转换为:
Business Unit: {
'Communication': {
Process: {
'Contributions': {
GEO: {
'Europe': {...}
GEO: :
'Global': {...}
你说的GEO是什么意思:{‘欧洲’:{…}又是GEO??重复的钥匙?嗨@Lamanus,哦,是的,我的错,GEO应该只有一个标签。