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