Python:itertools.product()的更快替代品? [英] Python: faster alternative for itertools.product()?
本文介绍了Python:itertools.product()的更快替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试查找长度= 22&的列表的所有可能组合.元素值= 1-9.
I'm trying to find all possible combinations of a list with length = 22 & element values = 1-9.
当我使用[i for i in itertools.product(range(1, 10), repeat=22)]
时,Python崩溃. Python有更快的替代方法吗?
When I use [i for i in itertools.product(range(1, 10), repeat=22)]
, Python crashes. Does Python have a faster alternative?
推荐答案
每个人都评论过,请尝试直接使用生成器,而不要使用列表. 查找所有组合尚不清楚.如果需要打印它们,请执行以下操作:
As everyone commented, try using the generator directly instead of using a list. finding all combinations is unclear. If you need to print them, do this:
for i in itertools.product(range(1, 10), repeat=22):
... #Don't actually print, that may block your computer for a long time.
如果您需要对这些值做些事情,然后告诉我们您需要什么.
if you need to do something on those values, then tell us what you need.
这篇关于Python:itertools.product()的更快替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文