Python: faster alternative for itertools.product()?

守給你的承諾、 提交于 2019-12-04 01:44:42

问题


I'm trying to find all possible combinations of a list with length = 22 & element values = 1-9.

When I use [i for i in itertools.product(range(1, 10), repeat=22)], Python crashes. Does Python have a faster alternative?


回答1:


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.



来源:https://stackoverflow.com/questions/34316346/python-faster-alternative-for-itertools-product

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!