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


Python Counter.__setitem__方法代码示例

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


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

示例1: test_MutableMapping

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_MutableMapping(self):
        for sample in [dict]:
            self.assertIsInstance(sample(), MutableMapping)
            self.assertTrue(issubclass(sample, MutableMapping))
        self.validate_abstract_methods(MutableMapping, '__contains__', '__iter__', '__len__',
            '__getitem__', '__setitem__', '__delitem__') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_collections.py

示例2: test_MutableSequence

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_MutableSequence(self):
        for sample in [tuple, str, bytes]:
            self.assertNotIsInstance(sample(), MutableSequence)
            self.assertFalse(issubclass(sample, MutableSequence))
        for sample in [list, bytearray, deque]:
            self.assertIsInstance(sample(), MutableSequence)
            self.assertTrue(issubclass(sample, MutableSequence))
        self.assertFalse(issubclass(str, MutableSequence))
        self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
            '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_collections.py

示例3: __setitem__

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def __setitem__(self, key, value):
        self.called = True
        Counter.__setitem__(self, key, value) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_collections.py

示例4: test_dict_setitem

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_dict_setitem(self):
        OrderedDict = self.OrderedDict
        od = OrderedDict()
        dict.__setitem__(od, 'spam', 1)
        self.assertNotIn('NULL', repr(od)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_collections.py

示例5: test_MutableSequence

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_MutableSequence(self):
        for sample in [tuple, str, bytes]:
            self.assertNotIsInstance(sample(), MutableSequence)
            self.assertFalse(issubclass(sample, MutableSequence))
        for sample in [list, bytearray]:
            self.assertIsInstance(sample(), MutableSequence)
            self.assertTrue(issubclass(sample, MutableSequence))
        self.assertFalse(issubclass(str, MutableSequence))
        self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
            '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:12,代码来源:test_collections.py

示例6: __setitem__

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def __setitem__(self, key, val):
        """
        Override ``Counter.__setitem__()`` to invalidate the cached N
        """
        self._N = None
        super(FreqDist, self).__setitem__(key, val) 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:8,代码来源:probability.py

示例7: test_MutableSequence_mixins

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_MutableSequence_mixins(self):
        # Test the mixins of MutableSequence by creating a miminal concrete
        # class inherited from it.
        class MutableSequenceSubclass(MutableSequence):
            def __init__(self):
                self.lst = []

            def __setitem__(self, index, value):
                self.lst[index] = value

            def __getitem__(self, index):
                return self.lst[index]

            def __len__(self):
                return len(self.lst)

            def __delitem__(self, index):
                del self.lst[index]

            def insert(self, index, value):
                self.lst.insert(index, value)

        mss = MutableSequenceSubclass()
        mss.append(0)
        mss.extend((1, 2, 3, 4))
        self.assertEqual(len(mss), 5)
        self.assertEqual(mss[3], 3)
        mss.reverse()
        self.assertEqual(mss[3], 1)
        mss.pop()
        self.assertEqual(len(mss), 4)
        mss.remove(3)
        self.assertEqual(len(mss), 3)
        mss += (10, 20, 30)
        self.assertEqual(len(mss), 6)
        self.assertEqual(mss[-1], 30)
        mss.clear()
        self.assertEqual(len(mss), 0)

################################################################################
### Counter
################################################################################ 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:44,代码来源:test_collections.py

示例8: test_MutableSequence_mixins

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import __setitem__ [as 别名]
def test_MutableSequence_mixins(self):
        # Test the mixins of MutableSequence by creating a minimal concrete
        # class inherited from it.
        class MutableSequenceSubclass(MutableSequence):
            def __init__(self):
                self.lst = []

            def __setitem__(self, index, value):
                self.lst[index] = value

            def __getitem__(self, index):
                return self.lst[index]

            def __len__(self):
                return len(self.lst)

            def __delitem__(self, index):
                del self.lst[index]

            def insert(self, index, value):
                self.lst.insert(index, value)

        mss = MutableSequenceSubclass()
        mss.append(0)
        mss.extend((1, 2, 3, 4))
        self.assertEqual(len(mss), 5)
        self.assertEqual(mss[3], 3)
        mss.reverse()
        self.assertEqual(mss[3], 1)
        mss.pop()
        self.assertEqual(len(mss), 4)
        mss.remove(3)
        self.assertEqual(len(mss), 3)
        mss += (10, 20, 30)
        self.assertEqual(len(mss), 6)
        self.assertEqual(mss[-1], 30)
        mss.clear()
        self.assertEqual(len(mss), 0)

################################################################################
### Counter
################################################################################ 
开发者ID:bkerler,项目名称:android_universal,代码行数:44,代码来源:test_collections.py


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