我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用collections.KeysView()。
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)])
def test_abc_registry(self): d = dict(a=1) self.assertIsInstance(d.viewkeys(), collections.KeysView) self.assertIsInstance(d.viewkeys(), collections.MappingView) self.assertIsInstance(d.viewkeys(), collections.Set) self.assertIsInstance(d.viewkeys(), collections.Sized) self.assertIsInstance(d.viewkeys(), collections.Iterable) self.assertIsInstance(d.viewkeys(), collections.Container) self.assertIsInstance(d.viewvalues(), collections.ValuesView) self.assertIsInstance(d.viewvalues(), collections.MappingView) self.assertIsInstance(d.viewvalues(), collections.Sized) self.assertIsInstance(d.viewitems(), collections.ItemsView) self.assertIsInstance(d.viewitems(), collections.MappingView) self.assertIsInstance(d.viewitems(), collections.Set) self.assertIsInstance(d.viewitems(), collections.Sized) self.assertIsInstance(d.viewitems(), collections.Iterable) self.assertIsInstance(d.viewitems(), collections.Container)
def keys(self): "D.keys() -> a set-like object providing a view on D's keys" return KeysView(self)
def keys(self): """ Get all the keys of the configuration. :return tuple: The keys of the configuration. """ return KeysView(self)
def viewkeys(self): """Set-like object providing a view of index keys. >>> index = Index('/tmp/diskcache/index') >>> index.clear() >>> index.update({'a': 1, 'b': 2, 'c': 3}) >>> keys_view = index.viewkeys() >>> 'b' in keys_view True :return: keys view """ return KeysView(self)
def keys(self): """Set-like object providing a view of index keys. >>> index = Index('/tmp/diskcache/index') >>> index.clear() >>> index.update({'a': 1, 'b': 2, 'c': 3}) >>> keys_view = index.keys() >>> 'b' in keys_view True :return: keys view """ return KeysView(self)
def keys(self): return KeysView(self)
def viewkeys(self): return collections.KeysView(self)