python - 为什么在这里设置相等中断?
问题描述
我有一个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”......但这不重要。
解决方案
推荐阅读
- python-3.x - 从数据框中过滤行
- c# - C# - 将字符串转换为可为空的 Guid?
- azure - Azure Functions - Always On 和 HTTP 触发器
- docker - 在 Github Actions 和查询中设置 Cassandra 容器
- sql - SQL IF 中的两个集合
- angular - RxJS 库中是否存在安全问题?
- java - 为什么在 Java 中使用可比较的接口?
- flutter - Flutter - 如何构建具有通用主页和可选登录功能的应用程序
- python - 使用 BeatifulSoup find_all 时未找到元素
- telegram - 下载发送到 Bot 的文件 (>20 MB) 是否有任何解决方法?我尝试使用“file_id”获取“file_path”,但它返回错误