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


Python OrderedDict.fromkeys方法代码示例

本文整理汇总了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)
开发者ID:aaronjoel,项目名称:cyordereddict,代码行数:11,代码来源:test_ordereddict.py

示例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')
开发者ID:aaronjoel,项目名称:cyordereddict,代码行数:15,代码来源:test_ordereddict.py

示例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])
开发者ID:kobotoolbox,项目名称:formpack,代码行数:40,代码来源:export.py

示例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])
开发者ID:chebee7i,项目名称:cyordereddict,代码行数:8,代码来源:test_ordereddict.py

示例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', ...)])")
开发者ID:chebee7i,项目名称:cyordereddict,代码行数:8,代码来源:test_ordereddict.py


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