我有一个类似这样的字典
{
'Host-A': {'requests':
{'GET /index.php/dashboard HTTP/1.0': {'code': '200', 'hit_count': 3},
'GET /index.php/cronjob HTTP/1.0': {'code': '200', 'hit_count': 4},
'GET /index.php/setup HTTP/1.0': {'code': '200', 'hit_count': 2}},
'total_hit_count': 9},
}
如您所见,对于
'Host-A'
,该值是一个包含每个页面收到的请求和命中次数的字典。问题是如何按降序排序'requests'
,以便我可以获得前几个请求。正确解决方案的输出示例应类似于:
{
'Host-A': {'requests':
{'GET /index.php/cronjob HTTP/1.0': {'code': '200', 'hit_count': 4},
'GET /index.php/dashboard HTTP/1.0': {'code': '200', 'hit_count': 3},
'GET /index.php/setup HTTP/1.0': {'code': '200', 'hit_count': 2}},
'total_hit_count': 9},
}
感谢您的帮助
OrderedDict
:https://docs.python.org/3/library/collections.html#ordereddict-objects - aikikode