MultiKeyDict

class deepfos.lib.utils.MultiKeyDict(*args, **kwargs)

分组字典

多个key对应一个值,同值的key属于一组,遍历时 只有“组长”会作为key出现。

>>> mkd = MultiKeyDict()
>>> mkd['group1'] = 1
>>> mkd['v1', 'group1'] = 1
>>> mkd['v2', 'group1'] = 1
>>> mkd['v3', 'group2'] = 2
>>> mkd['v4', 'group2'] = 2
>>> list(mkd.keys())
['group1', 'group2']
>>> list(mkd.items())
[('group1', 1), ('group2', 2)]
>>> mkd['v1']
1
>>> mkd['group1']
1
>>> 'v3' in mkd
True