在Python3.3中,ChainMap类已添加到collections模块:AChainMapclassisprovidedforquicklylinkinganumberofmappingssotheycanbetreatedasasingleunit.Itisoftenmuchfasterthancreatinganewdictionaryandrunningmultipleupdate()calls.例子:>>>fromcollectionsimportChainMap>>>x={'a':1,'b':2}>>>y={'b':10,'c':11}>>>z=ChainMap(y,x
在Python3.3中,ChainMap类已添加到collections模块:AChainMapclassisprovidedforquicklylinkinganumberofmappingssotheycanbetreatedasasingleunit.Itisoftenmuchfasterthancreatinganewdictionaryandrunningmultipleupdate()calls.例子:>>>fromcollectionsimportChainMap>>>x={'a':1,'b':2}>>>y={'b':10,'c':11}>>>z=ChainMap(y,x
Python的ChainMap使您能够将多个映射链接在一起,以便查找按顺序搜索所有映射,直到找到匹配的键。这是关于它的许多文章之一:https://dzone.com/articles/python-201-what-is-a-chainmap以及官方文档:https://docs.python.org/3/library/collections.html有人知道用Go编写的现有等效包吗?到目前为止,我一直找不到一个,如果确实存在的话,我想避免重新发明轮子。 最佳答案 没有包,但实现类似的东西相当简单:让我们使用map[string