本文整理汇总了Python中cyordereddict.OrderedDict.fromkeys方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.fromkeys方法的具体用法?Python OrderedDict.fromkeys怎么用?Python OrderedDict.fromkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.fromkeys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_detect_deletion_during_iteration
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import fromkeys [as 别名]
def test_detect_deletion_during_iteration(self):
od = OrderedDict.fromkeys('abc')
it = iter(od)
key = next(it)
del od[key]
with self.assertRaises(Exception):
# Note, the exact exception raised is not guaranteed
# The only guarantee that the next() will not succeed
next(it)
示例2: test_move_to_end
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import fromkeys [as 别名]
def test_move_to_end(self):
od = OrderedDict.fromkeys('abcde')
self.assertEqual(list(od), list('abcde'))
od.move_to_end('c')
self.assertEqual(list(od), list('abdec'))
od.move_to_end('c', 0)
self.assertEqual(list(od), list('cabde'))
od.move_to_end('c', 0)
self.assertEqual(list(od), list('cabde'))
od.move_to_end('e')
self.assertEqual(list(od), list('cabde'))
with self.assertRaises(KeyError):
od.move_to_end('x')
示例3: __init__
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import fromkeys [as 别名]
def __init__(self, form_versions, lang=UNSPECIFIED_TRANSLATION,
group_sep="/", hierarchy_in_labels=False,
version_id_keys=[],
multiple_select="both", copy_fields=(), force_index=False,
title="submissions"):
self.lang = lang
self.group_sep = group_sep
self.title = title
self.versions = form_versions
self.copy_fields = copy_fields
self.force_index = force_index
self.herarchy_in_labels = hierarchy_in_labels
self.version_id_keys = version_id_keys
# If some fields need to be arbitrarly copied, add them
# to the first section
if copy_fields:
first_version = next(iter(form_versions.values()))
first_section = next(iter(first_version.sections.values()))
for name in copy_fields:
dumb_field = CopyField(name, section=first_section)
first_section.fields[name] = dumb_field
# this deals with merging all form versions headers and labels
params = (lang, group_sep, hierarchy_in_labels, multiple_select)
res = self.get_fields_and_labels_for_all_versions(*params)
self.sections, self.labels = res
self.reset()
# Some cache to improve perfs on large datasets
self._row_cache = {}
self._empty_row = {}
for section_name, fields in self.sections.items():
self._row_cache[section_name] = OrderedDict.fromkeys(fields, '')
self._empty_row[section_name] = dict(self._row_cache[section_name])
示例4: test_views
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import fromkeys [as 别名]
def test_views(self):
s = 'the quick brown fox jumped over a lazy dog yesterday before dawn'.split()
od = OrderedDict.fromkeys(s)
self.assertEqual(list(od.viewkeys()), s)
self.assertEqual(list(od.viewvalues()), [None for k in s])
self.assertEqual(list(od.viewitems()), [(k, None) for k in s])
示例5: test_repr_recursive
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import fromkeys [as 别名]
def test_repr_recursive(self):
# See issue #9826
od = OrderedDict.fromkeys('abc')
od['x'] = od
self.assertEqual(repr(od),
"OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")