首页 > 其他 > 详细

调用list(itertools.combinations(keys,3))出现MemoryError的解决办法

时间:2019-02-28 17:41:40      阅读:222      评论:0      收藏:0      [点我收藏+]

在python3.6中,如下例子:

keys = list(newKeywords.keys())

resultkeys = list(itertools.combinations(keys,3))

当上面中的Keys太长时会发生MemoryError错误,解决办法:

keys = list(newKeywords.keys())

resultkeys = itertools.combinations(keys,3)

for rkey in resultkeys:
  print(rkey)

 

据下面链接中所说,只有当前用到的组合才存放在内存中。

原文如下:

by doing this, python will keep in memory only the currently used permutation, not all the permutations (in term of memory usage, it is really better ;) )

 

reference:https://stackoverflow.com/questions/6503388/prevent-memory-error-in-itertools-permutation

调用list(itertools.combinations(keys,3))出现MemoryError的解决办法

原文:https://www.cnblogs.com/lijavasy/p/10451816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!