gpt4 book ai didi

python - 并行化以在 python 中添加计数器

转载 作者:太空宇宙 更新时间:2023-11-03 20:53:51 24 4
gpt4 key购买 nike

有一个要添加的词典列表。

list_of_dictionaries = [{"a":1,"b":2,...},{"a":2,"b":2,...},...]
combined_dictionary = {}

for dictionary in list_of_dictionaries:
combined_dictionary = Counter(combined_dictionary) + Counter(dictionary)

print(combined_dictionary)

我想使用多个核心来完成此操作,因为 list_of_dictionaries 非常大。

有人可以帮我吗?

我已经在线阅读了 30 多个与多处理相关的解决方案(包括在 multiprocessing.pool.process 中使用共享字典),但我没有注意到任何可以解决我的问题的解决方案。我希望有人能为该任务提供更相关的链接或一些代码。

谢谢!

杰瑞

最佳答案

如果您真的想尽可能高效地添加此类字典,那么没有比 MapReduce 更好的了。

MapReduce 因 Google 使用它以类似于您所描述的方式添加和处理大量数据而闻名。它将工作无缝扩展到多个核心,并可用于在网络中的一群计算机上扩展工作。

<小时/>

资源:

关于python - 并行化以在 python 中添加计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56142816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com