當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。