本文整理匯總了Python中collections.OrderedDict.__getitem__方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.__getitem__方法的具體用法?Python OrderedDict.__getitem__怎麽用?Python OrderedDict.__getitem__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類collections.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.__getitem__方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
"""Get items from a TableColumns object."""
if isinstance(item, six.string_types):
try:
return OrderedDict.__getitem__(self, item)
except KeyError:
try:
return OrderedDict.__getitem__(self, item.lower())
except KeyError:
return OrderedDict.__getitem__(self, item.upper())
elif isinstance(item, int):
return self.values()[item]
elif isinstance(item, tuple):
return self.__class__([self[x] for x in item])
elif isinstance(item, slice):
return self.__class__([self[x] for x in list(self)[item]])
else:
raise IndexError('Illegal key or index value for {} object'
.format(self.__class__.__name__))
示例2: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
"""Get items from a TableColumns object.
::
tc = TableColumns(cols=[Column(name='a'), Column(name='b'), Column(name='c')])
tc['a'] # Column('a')
tc[1] # Column('b')
tc['a', 'b'] # <TableColumns names=('a', 'b')>
tc[1:3] # <TableColumns names=('b', 'c')>
"""
if isinstance(item, str):
return OrderedDict.__getitem__(self, item)
elif isinstance(item, (int, np.integer)):
return self.values()[item]
elif (isinstance(item, np.ndarray) and item.shape == () and item.dtype.kind == 'i'):
return self.values()[item.item()]
elif isinstance(item, tuple):
return self.__class__([self[x] for x in item])
elif isinstance(item, slice):
return self.__class__([self[x] for x in list(self)[item]])
else:
raise IndexError('Illegal key or index value for {} object'
.format(self.__class__.__name__))
示例3: get
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def get(self, key):
""" Basic getter that renews LRU status upon inspection
Args:
key (str): immutable dictionary key
"""
value = OrderedDict.__getitem__(self, key)
self.move_to_end(key)
return value
示例4: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
if type(item) is list:
return self.reverse[item[0]]
else:
return dict.__getitem__(self, item)
示例5: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
try:
return OrderedDict.__getitem__(self, key)
except KeyError:
return self.__missing__(key)
示例6: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
key = key.lower() # all keys should be lower-case to make editing easier
try:
return OrderedDict.__getitem__(self, key)
except KeyError:
return self.__missing__(key)
示例7: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self: Dict[CacheKey, CacheValue], key: CacheKey) -> CacheValue:
"""Gets the item, but also makes it most recent."""
value: CacheValue = OrderedDict.__getitem__(self, key)
OrderedDict.__delitem__(self, key)
OrderedDict.__setitem__(self, key, value)
return value
示例8: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
if OrderedDict.__contains__(self, key):
val = OrderedDict.__getitem__(self, key)
elif '.' in key:
keys = key.split('.')
val = self[keys[0]]
for k in keys[1:]:
val = val[k]
else:
return OrderedDict.__getitem__(self, key)
return val
示例9: __contains__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __contains__(self, key):
# Cannot use "key in" due to recursion, reusing rules for dotted keys from __getitem__
try:
self[key]
return True
except KeyError:
return False
示例10: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key, *args, **kwargs):
# Get the key and remove it from the cache, or raise KeyError
value = OrderedDict.__getitem__(self, key)
del self[key]
# Insert the (key, value) pair on the front of the cache
OrderedDict.__setitem__(self, key, value)
# Return the value from the cache
return value
示例11: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
if isinstance(key, (int, slice)):
return super(EnrichedTuple, self).__getitem__(key)
else:
return self.__getitem_hook__(key)
示例12: __getitem__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
e = OrderedDict.__getitem__(self, item)
del self[item]
OrderedDict.__setitem__(self, item, e)
return e