当前位置: 首页>>代码示例>>Python>>正文


Python Counter.__add__方法代码示例

本文整理汇总了Python中collections.Counter.__add__方法的典型用法代码示例。如果您正苦于以下问题:Python Counter.__add__方法的具体用法?Python Counter.__add__怎么用?Python Counter.__add__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.Counter的用法示例。


在下文中一共展示了Counter.__add__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __add__

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __add__ [as 别名]
    def __add__(self, other):
        """Add together, with recursion.  The basic idea is that the set of keys
        should be added together and then recurse the addition to the values where keys are shared
        otherwise just add the value.

        >>> m, m2 = Mdict('a'), Mdict('abb')
        >>> m + m2 == {'a':2, 'b':2}
        True
        >>> m + 1 == {None:1, 'a':1}
        True
        >>> m['a'] = m2  #now fractal
        >>> m == {'a': {'a':1, 'b':2}}
        True
        >>> m + m + 1 == {'a': {'a':2, 'b':4}, None: 1}
        True
        """
        try: # need to add (union) of keys, and then recurse into values of common keys
            return Mdict(Counter.__add__(self, other)) #Counter.__add__(self, other)
        except TypeError: #must've been an integer for other
            return Mdict(Counter.__add__(self, Counter({None: other})))
开发者ID:theProphet,项目名称:Pangaia,代码行数:22,代码来源:metadict.py

示例2: __add__

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __add__ [as 别名]
 def __add__(self, other):
     return Factorization(Counter.__add__(self, other))
开发者ID:phincallahan,项目名称:project-euler,代码行数:4,代码来源:factorization.py

示例3: __add__

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __add__ [as 别名]
 def __add__(self, other):
     return Vector(Counter.__add__(self, other))
开发者ID:sankethkatta,项目名称:tpro,代码行数:4,代码来源:__init__.py


注:本文中的collections.Counter.__add__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。