我想找到从[0,0,0,0,0,0]到[1,1,1,1,1,1]的所有可能路径。例如:
path_i = [[0,0,0,0,0,0], [0,1,0,0,0,0], [0,1,1,0,0,0], [0,1,1,0,0,1], …
所以你们我们有 7! 找到路径的方法,你可以使用 itertools.permutations 为了那个原因:
7!
itertools.permutations
from itertools import permutations paths = permutations(range(7), 7) list_paths = [] for path in paths: tmp = [0]*7 list_path = [tmp[:]] for index in path: tmp[index] = 1 list_path.append(tmp[:]) list_paths.append(list_path)
你所有的路径都在 list_paths
list_paths