object_pairs_hook is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict() will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority.
您可以将} ,后者将使用相同的键将值收集到列表中:
^{1}$object_pairs_hook
传递给^{输出:
^{pr2}$在上面的钩子接收} ,其中值是列表。一旦迭代元组,它将生成结果
(key, value)
元组的list
,它将这些元组存储到^{dict
,其中value是list,如果有多个项具有给定的键。在Python文档对钩子有以下描述:
相关问题 更多 >
编程相关推荐