當前位置: 首頁>>代碼示例>>Python>>正文


Python OrderedDict.items方法代碼示例

本文整理匯總了Python中diffpy.srfit.util.ordereddict.OrderedDict.items方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.items方法的具體用法?Python OrderedDict.items怎麽用?Python OrderedDict.items使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在diffpy.srfit.util.ordereddict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.items方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_setdefault

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_setdefault(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     pair_order = list(od.items())
     self.assertEqual(od.setdefault('a', 10), 3)
     # make sure order didn't change
     self.assertEqual(list(od.items()), pair_order)
     self.assertEqual(od.setdefault('x', 10), 10)
     # make sure 'x' is added to the end
     self.assertEqual(list(od.items())[-1], ('x', 10))
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:13,代碼來源:testordereddict.py

示例2: test_delitem

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_delitem(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     del od['a']
     self.assert_('a' not in od)
     self.assertRaises(KeyError, od.__delitem__, 'a')
     self.assertEqual(list(od.items()), pairs[:2] + pairs[3:])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:9,代碼來源:testordereddict.py

示例3: test_reinsert

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_reinsert(self):
     # Given insert a, insert b, delete a, re-insert a,
     # verify that a is now later than b.
     od = OrderedDict()
     od['a'] = 1
     od['b'] = 2
     del od['a']
     od['a'] = 1
     self.assertEqual(list(od.items()), [('b', 2), ('a', 1)])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:11,代碼來源:testordereddict.py

示例4: test_iterators

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_iterators(self):
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     shuffle(pairs)
     od = OrderedDict(pairs)
     self.assertEqual(list(od), [t[0] for t in pairs])
     self.assertEqual(list(od.keys()), [t[0] for t in pairs])
     self.assertEqual(list(od.values()), [t[1] for t in pairs])
     self.assertEqual(list(od.items()), pairs)
     self.assertEqual(list(reversed(od)),
                      [t[0] for t in reversed(pairs)])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:12,代碼來源:testordereddict.py

示例5: test_update

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
    def test_update(self):
        self.assertRaises(TypeError, OrderedDict().update, [('a', 1), ('b',
            2)], None)                        # too many args
        pairs = [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
        od = OrderedDict()
        od.update(dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)                                 # dict input
        od = OrderedDict()
        od.update(**dict(pairs))
        self.assertEqual(sorted(od.items()), pairs)                                 # kwds input
        od = OrderedDict()
        od.update(pairs)
        self.assertEqual(list(od.items()), pairs)                                   # pairs input
        od = OrderedDict()
        od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
        self.assertEqual(list(od.items()), pairs)                                   # mixed input

        # Make sure that direct calls to update do not clear previous contents
        # add that updates items are not moved to the end
        d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
        d.update([('e', 5), ('f', 6)], g=7, d=4)
        self.assertEqual(list(d.items()),
            [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7)])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:25,代碼來源:testordereddict.py

示例6: test_init

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
    def test_init(self):
        self.assertRaises(TypeError, OrderedDict, ([('a', 1), ('b', 2)], None))
                # too many args
        pairs = [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
        self.assertEqual(sorted(OrderedDict(dict(pairs)).items()), pairs)           # dict input
        self.assertEqual(sorted(OrderedDict(**dict(pairs)).items()), pairs)         # kwds input
        self.assertEqual(list(OrderedDict(pairs).items()), pairs)                   # pairs input
        self.assertEqual(list(OrderedDict([('a', 1), ('b', 2), ('c', 9), ('d', 4)],
                                          c=3, e=5).items()), pairs)                # mixed input

        # make sure no positional args conflict with possible kwdargs
        self.assertEqual(inspect.getargspec(OrderedDict.__dict__['__init__'])[0],
                         ['self'])

        # Make sure that direct calls to __init__ do not clear previous contents
        d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
        d.__init__([('e', 5), ('f', 6)], g=7, d=4)
        self.assertEqual(list(d.items()),
            [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7)])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:21,代碼來源:testordereddict.py

示例7: test_copying

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_copying(self):
     # Check that ordered dicts are copyable, deepcopyable, picklable,
     # and have a repr/eval round-trip
     pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
     od = OrderedDict(pairs)
     update_test = OrderedDict()
     update_test.update(od)
     for i, dup in enumerate([
                 od.copy(),
                 copy.copy(od),
                 copy.deepcopy(od),
                 pickle.loads(pickle.dumps(od, 0)),
                 pickle.loads(pickle.dumps(od, 1)),
                 pickle.loads(pickle.dumps(od, 2)),
                 pickle.loads(pickle.dumps(od, -1)),
                 eval(repr(od)),
                 update_test,
                 OrderedDict(od),
                 ]):
         self.assert_(dup is not od)
         self.assertEquals(dup, od)
         self.assertEquals(list(dup.items()), list(od.items()))
         self.assertEquals(len(dup), len(od))
         self.assertEquals(type(dup), type(od))
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:26,代碼來源:testordereddict.py

示例8: test_setitem

# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import items [as 別名]
 def test_setitem(self):
     od = OrderedDict([('d', 1), ('b', 2), ('c', 3), ('a', 4), ('e', 5)])
     od['c'] = 10           # existing element
     od['f'] = 20           # new element
     self.assertEqual(list(od.items()),
                      [('d', 1), ('b', 2), ('c', 10), ('a', 4), ('e', 5), ('f', 20)])
開發者ID:XiaohaoYang,項目名稱:diffpy.srfit,代碼行數:8,代碼來源:testordereddict.py


注:本文中的diffpy.srfit.util.ordereddict.OrderedDict.items方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。