【发布时间】:2020-02-02 03:25:17
【问题描述】:
我可以用 itertools 做到这一点:
list(permutations([1,2,3],2))
: [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
但我也如何生成:
(1,1),(2,2),(3,3)
当然不用单独做:[(i,i) for i in range(4)]
【问题讨论】:
-
product([1,2,3], repeat=2)也使用 itertools 怎么样? -
ooo.. 我明白了..我试过 product([1,2,3], 2) ;)
-
TypeError: 'int' 对象不可迭代
标签: python repeat itertools permute