我需要长度为k的0,1所有可能组合。
假设k=2,我想要 (0,0), (0,1), (1,0), (1,1)
我试过不同的itertools
函数,但没有找到我需要的。
>>> list(itertools.combinations_with_replacement([0,1], 2))
[(0, 0), (0, 1), (1, 1)]
>>> list(itertools.product([0,1], [0,1])) #does not work if k>2
[(0, 0), (0, 1), (1, 0), (1, 1)]