在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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-08-01
  • 2021-11-18
  • 2021-08-31
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案