0
在以下代碼中,雖然'c'和'd'都包含3個項目和全部3個項目,但是從循環產品中的對象'c'打印的唯一項目是第一個項目'd'正確迭代。Python itertools.combinations early cutoff
from itertools import combinations
c,d = combinations(map(str, range(3)),2), combinations(map(str, range(3)),2)
for x in c:
for y in d:
print(x,y)
列表生成列表解決這個問題,打印9行,但爲什麼這首先發生?
它是這麼簡單!我一直認爲第一臺發電機出現了問題。 +1爲基於itertools.product的方法。 –