【发布时间】:2019-07-16 17:29:38
【问题描述】:
我有清单:
list_a = set(["A", "B", "C", "D", "E", "F"])
list_b = set(["1", "2", "3", "4", "5", "6"])
list_c = set(["red", "yellow", "blue", "green"])
我想找出这些列表的可能组合的总数(每个列表一项)
使用较小的列表很容易实现这一点
import itertools as it
list_set = [list_a, list_b, list_c]
len(list(it.product(*list_of_unq_vars)))
这将返回组合的数量。
但是对于较大的列表,我会遇到内存错误。
有没有办法以这种方式计算可能组合的数量,而无需实际创建组合本身(就像我在上面所做的那样)?
非常感谢, J
【问题讨论】:
-
len(list_a) * len(list_b) * len(list_c)? -
将每个列表的所有项目的数量相乘(就像@meowgoesthedog 指出的那样)
-
@meowgoesthedog 没有解决你的问题,你的意思是别的吗?
标签: python python-3.x itertools