本文整理汇总了Python中collections.abc.ItemsView方法的典型用法代码示例。如果您正苦于以下问题:Python abc.ItemsView方法的具体用法?Python abc.ItemsView怎么用?Python abc.ItemsView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections.abc
的用法示例。
在下文中一共展示了abc.ItemsView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_MutableMapping_subclass
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def test_MutableMapping_subclass(self):
# Test issue 9214
mymap = UserDict()
mymap['red'] = 5
self.assertIsInstance(mymap.keys(), Set)
self.assertIsInstance(mymap.keys(), KeysView)
self.assertIsInstance(mymap.items(), Set)
self.assertIsInstance(mymap.items(), ItemsView)
mymap = UserDict()
mymap['red'] = 5
z = mymap.keys() | {'orange'}
self.assertIsInstance(z, set)
list(z)
mymap['blue'] = 7 # Shouldn't affect 'z'
self.assertEqual(sorted(z), ['orange', 'red'])
mymap = UserDict()
mymap['red'] = 5
z = mymap.items() | {('orange', 3)}
self.assertIsInstance(z, set)
list(z)
mymap['blue'] = 7 # Shouldn't affect 'z'
self.assertEqual(sorted(z), [('orange', 3), ('red', 5)])
示例2: __hash__
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def __hash__(self): # lgtm [py/equals-hash-mismatch]
"""The hash of this bidict as determined by its items."""
if getattr(self, '_hash', None) is None:
# pylint: disable=protected-access,attribute-defined-outside-init
self._hash = ItemsView(self)._hash()
return self._hash
# * Code review nav *
#==============================================================================
# ← Prev: _base.py Current: _frozenbidict.py Next: _mut.py →
#==============================================================================
示例3: __hash__
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def __hash__(self):
return ItemsView(self._mapping)._hash() # pylint: disable=protected-access
示例4: items
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def items(self):
"D.items() -> a set-like object providing a view on D's items"
return ItemsView(self)
示例5: items
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def items(self):
"""D.items() => a set-like object providing a view on D's items"""
return stdlib_collections.ItemsView(self)
示例6: test_issue26915
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ItemsView [as 别名]
def test_issue26915(self):
# Container membership test should check identity first
class CustomEqualObject:
def __eq__(self, other):
return False
class CustomSequence(Sequence):
def __init__(self, seq):
self._seq = seq
def __getitem__(self, index):
return self._seq[index]
def __len__(self):
return len(self._seq)
nan = float('nan')
obj = CustomEqualObject()
seq = CustomSequence([nan, obj, nan])
containers = [
seq,
ItemsView({1: nan, 2: obj}),
ValuesView({1: nan, 2: obj})
]
for container in containers:
for elem in container:
self.assertIn(elem, container)
self.assertEqual(seq.index(nan), 0)
self.assertEqual(seq.index(obj), 1)
self.assertEqual(seq.count(nan), 2)
self.assertEqual(seq.count(obj), 1)