我有一个字典,它有两个键值,每个键值都指向一个本身就是字典的值。现在我关心的是提取值的键值,而不管它们的第一个键是什么。这两个值的键既相同又不同。你知道吗
我需要得到一个单独的字典,其中不同的键保持相同,而两个字典中的键相同,因此有值更新,即它们相加。你知道吗
with open('report.json') as json_file:
data = json.load(json_file)
print(data['behavior']['apistats'])
输出包括:
{
"2740": {
"NtDuplicateObject": 2,
"NtOpenSection": 1,
"GetSystemWindowsDirectoryW": 23,
"NtQueryValueKey": 32,
"NtClose": 427,
"NtOpenMutant": 2,
"RegCloseKey": 8
},
"3908": {
"RegCreateKeyExW": 2,
"GetNativeSystemInfo": 1,
"NtOpenSection": 1,
"CoUninitialize": 6,
"RegCloseKey": 27,
"GetSystemInfo": 1,
"CreateToolhelp32Snapshot": 180,
"UnhookWindowsHookEx": 2,
"GetSystemWindowsDirectoryW": 6,
"NtQueryValueKey": 6,
"NtClose": 427
}
}
但是我需要一个字典,其中相同的'apistats'
值作为一个新值相加,并且键不重复,而不管父键'2740'
和'3908'
。你知道吗
你可以用
groupby
来解决它:资源:
相关问题 更多 >
编程相关推荐