Python combination with replacement

前端 未结 1 1373
独厮守ぢ
独厮守ぢ 2020-12-21 16:51

Below is my code

import itertools
a = [1,2,3]
for i in itertools.combination_with_replacement(a,3):
    print i

Output

(1,          


        
相关标签:
1条回答
  • 2020-12-21 17:05

    You want cartesian product, not combinations.

    import itertools
    print list(itertools.product([1, 2, 3], repeat=3))
    
    0 讨论(0)
提交回复
热议问题