本文整理汇总了Python中cobra.DictList.pop方法的典型用法代码示例。如果您正苦于以下问题:Python DictList.pop方法的具体用法?Python DictList.pop怎么用?Python DictList.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.DictList
的用法示例。
在下文中一共展示了DictList.pop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRemoval
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import pop [as 别名]
def testRemoval(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(2, 10))
del obj_list[3]
self.assertNotIn("test5", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
self.assertEqual(len(obj_list), 7)
del obj_list[3:5]
self.assertNotIn("test6", obj_list)
self.assertNotIn("test7", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
self.assertEqual(len(obj_list), 5)
removed = obj_list.pop(1)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
self.assertEqual(removed.id, "test3")
self.assertNotIn("test3", obj_list)
self.assertEqual(len(obj_list), 4)
removed = obj_list.pop()
self.assertEqual(removed.id, "test9")
self.assertNotIn(removed.id, obj_list)
self.assertEqual(len(obj_list), 3)
示例2: test_removal
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import pop [as 别名]
def test_removal(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(2, 10))
del obj_list[3]
assert "test5" not in obj_list
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert len(obj_list) == 7
del obj_list[3:5]
assert "test6" not in obj_list
assert "test7" not in obj_list
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert len(obj_list) == 5
removed = obj_list.pop(1)
assert obj_list.index(obj_list[-1]) == len(obj_list) - 1
assert removed.id == "test3"
assert "test3" not in obj_list
assert len(obj_list) == 4
removed = obj_list.pop()
assert removed.id == "test9"
assert removed.id not in obj_list
assert len(obj_list) == 3