首页 > 解决方案 > 为什么在这里设置相等中断?

问题描述

我有一个f定义如下的函数:

def f(doc):
    return filter(lambda ent: ..., doc.ents)

doc是一个 Spacy 文档对象并doc.ents返回一个生成器对象。还有doc.noun_chunks一个返回生成器对象。然而奇怪的事情发生了:

>>> a = list(f(doc))
[Apple, Banana]

>>> b = list(doc.noun_chunks)
[Banana, Apple]

>>> a[0] == b[1]
True

>>> a[1] == b[0]
True

>>> set(a) == set(b)
False

>>> list(set(a))[0] == list(set(b))[1]
True

>>> list(set(a))[1] == list(set(b))[0]
True

>>> set(list(set(a))) == set(list(set(b)))
False

为什么设置的平等在这里不起作用?!

PS 我正在使用 Spacy 为客户编写一个应用程序,所以很遗憾无法在此处粘贴完整的代码,并且还伪造了名称“f”、“Apple”和“Banana”......但这不重要。

标签: pythonsetspacy

解决方案


推荐阅读