2024-10-02 16:31:54 发布
网友
在编写一个查找列表所有不同组合的程序时,我发现了很多关于使用intertools.product()而不是{}的线程,就像我一直在做的那样。没有人解释为什么你应该使用intertools.产品. 我想知道这是如何影响我的程序输出。在
intertools.product()
From Python documentation
itertools.product(*iterables[, repeat])Cartesian product of input iterables.Equivalent to nested for-loops in a generator expression. For example, product(A, B) returns the same as ((x,y) for x in A for y in B).
itertools.product(*iterables[, repeat])
Cartesian product of input iterables.
Equivalent to nested for-loops in a generator expression. For example, product(A, B) returns the same as ((x,y) for x in A for y in B).
换句话说:
for x, y in itertools.product(A, B):
替换
编辑:
itertolls.COUNDATIONS U与U替换()将使用single iterable并生成其给定长度元素的所有可能组合;
OLS.ITERTOR产品()将生成来自多个iterable的值的组合,其中结果元组的元素0来自 第一个iterable,元素1-从第二个开始,等等。
From Python documentation
换句话说:
替换
^{pr2}$编辑:
itertolls.COUNDATIONS U与U替换()将使用single iterable并生成其给定长度元素的所有可能组合;
OLS.ITERTOR产品()将生成来自多个iterable的值的组合,其中结果元组的元素0来自 第一个iterable,元素1-从第二个开始,等等。
相关问题 更多 >
编程相关推荐