[{"name": "thisisname1", "filebytestotal": 334632,"memorybytes": 5467234},
{"name": "thisisname2", "filebytestotal": 2351, "memorybytes": 324523},
{"name": "thisisname3", "filebytestotal": 2314651, "memorybytes": 2235},
{"name": "thisisname1", "filebytestotal": 13432, "memorybytes": 546534},
{"name": "thisisname1", "filebytestotal": 32342, "memorybytes": 341234}]
大家好,我试着找出如何为所有匹配的“name”值生成键filebytes和memorybytes的平均值。 我的问题是我不知道´我不知道如何通过总列表中的字典来搜索模式
提前谢谢
这是一个使用“memorybytes”键的示例
FileByTestTotal有一个问题,因为您有两个不同的键: “filebytes”和“filebytestotal”。如果你在数组的所有元素中都有这个键,那么你可以通过改变理解列表中的键来使用相同的功能
解决这个问题的一种方法是将它重组为一个列表字典。像这样的
这使用^{} ,它用默认值填充任何空键。你可以用内置字典来写,但这样可以省下几行
相关问题 更多 >
编程相关推荐