本文整理汇总了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__')
示例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')
示例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)
示例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))
示例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')
示例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)
示例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
################################################################################
示例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
################################################################################