python - 如何在 Python 中使用多处理进行列表减法
问题描述
我正在使用以下代码进行列表减法。
X = [1,2,3,4,5,6]
Y = [4,5]
# to find the elements which in X but not in Y
result = [e for e in X if e not in Y]
# expected result: [1,2,3,6]
由于 X 和 Y 中有数百万个元素,
减法运算很慢,
单个 CPU 使用率达到 100%(剩下其他 10+ 个 CPU 使用率 0%),也许使用多处理可能会改善这种情况。
如何在 Python 中使用多处理来做到这一点?
from multiprocessing import Pool
????
pool = Pool(11)
pool.map(?, ?)
pool.close()
pool.join()
解决方案
推荐阅读
- google-apps-script - google.script.run 不适用于某些用户的 Chrome 浏览器
- amazon-web-services - 将 CSV 从 Heroku Redis DB 导出到 AWS S3 存储桶
- python - 如何获取N维np数组中唯一数组元素的数量?
- kubernetes - 尽管选择器,Kubernetes 服务未创建端点
- flutter - Flutter:如何将条形码扫描值传递给 TextFormField
- java - 如何在 Resilience4j Spring starter 中配置事件
- python - python - 使用 BeautifulSoup 抓取网页的更有效方法
- android - 清除导航返回堆栈和重新创建活动
- node.js - 错误:监听 EADDRINUSE:地址已在使用 :::3000 - Digitalocean
- c - C 非法指令