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


Python abc.ItemsView方法代码示例

本文整理汇总了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)]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_collections.py

示例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 →
#============================================================================== 
开发者ID:jab,项目名称:bidict,代码行数:14,代码来源:_frozenbidict.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 
开发者ID:jab,项目名称:bidict,代码行数:4,代码来源:_types.py

示例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) 
开发者ID:benbovy,项目名称:xarray-simlab,代码行数:5,代码来源:utils.py

示例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) 
开发者ID:compas-dev,项目名称:compas,代码行数:5,代码来源:_mutablemapping.py

示例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) 
开发者ID:bkerler,项目名称:android_universal,代码行数:30,代码来源:test_collections.py


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