Python set item memebership condition test failed

时间:2014-08-09 16:54:22

标签: python-2.7 set

我有一组对象,对于其中一些,成员资格测试因某些原因未知原因而失败。

基本上我无法通过search_results.remove(entry)从集合中删除项目,因为python“认为”该项目不在那里并且它会抛出KeyError异常。当我手动想要检查它是否存在时,它会返回False,但如果我将set()转换为list(),则会返回True

>>> entry in search_results
False
>>> test = list(search_results)
>>> entry in test
True
>>> search_results.remove(entry)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
KeyError: <Entry(title=Mock,state=done)>
>>> test.remove(entry)
>>> entry in test
False

使用Python 2.7.8

0 个答案:

没有答案
相关问题