如何实现有序的、默认的DECT?我想把OrderedDict()和defaultdict()从…collections在一个对象中,这将是一个有序的、默认的dict.这个是可能的吗?
3 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
from collections import OrderedDict, defaultdictclass OrderedDefaultDict(OrderedDict, defaultdict): def __init__(self, default_factory=None, *args, **kwargs): #in python3 you can omit the args to super super(OrderedDefaultDict, self).__init__(*args, **kwargs) self.default_factory = default_factory
help(OrderedDefaultDict)
class OrderedDefaultDict(collections.OrderedDict, collections.defaultdict) | Method resolution order: | OrderedDefaultDict | collections.OrderedDict | collections.defaultdict | __builtin__.dict | __builtin__.object
OrderedDefaultDict
OrderedDict
defaultdict
__builtin__.dict
添加回答
举报
0/150
提交
取消