python: m个位置,每个位置有n种可能,求所有排列结果

>>> import itertools 
>>> m, n = 3, 2
>>> paths = list(itertools.product(range(n), repeat=m))
>>> print(paths)
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
posted @ 2022-09-23 22:41  CJK'sBLOG  阅读(72)  评论(0)    收藏  举报