我从外部 API 获取结果作为字典的格式:
{data:[{values:[{'end_time':'2013-10-03T07:00:00+0000', value:{'mobile':4, 'search':3}}, {'end_time':'2013-10-04T07:00:00+0000', value:{'source':2}}]}]}
我想将其转换为具有以下格式的字典:
{'2013-10-03T07:00:00+0000':{'mobile':4, 'search':3},'2013-10-04T07:00:00+0000':{'source':2}}
当我尝试以下操作时,我收到以SyntaxError: keyword can't be an expression
开头的行的错误output_dict
:
def dict_cleaner(input_dict):
for day in input_dict['data'][0]['values'][0]['end_time']:
output_dict = dict(input_dict['data'][0]['values'][0]['end_time']=input_dict['data'][0]['values'][0]['value'])
return output_dict
我在这里做错了什么?