itertools.permutations - это хорошая функция, которая помогает вам возвращать все возможные параметры списка. удаление 0 (начальных точек) начала и конца списка приводит к следующей гипотетической routelist
Это может помочь вам:
import itertools
routelist = [5, 8, 52, 16, 87]
matrix = list(itertools.permutations(routelist, 5))
print(matrix)
output:
[(5, 8, 52, 16, 87), (5, 8, 52, 87, 16), (5, 8, 16, 52, 87), (5, 8, 16, 87, 52), (5, 8, 87, 52, 16), (5, 8, 87, 16, 52), (5, 52, 8, 16, 87), (5, 52, 8, 87, 16), (5, 52, 16, 8, 87), (5, 52, 16, 87, 8), (5, 52, 87, 8, 16), (5, 52, 87, 16, 8), (5, 16, 8, 52, 87), (5, 16, 8, 87, 52), (5, 16, 52, 8, 87), (5, 16, 52, 87, 8), (5, 16, 87, 8, 52), (5, 16, 87, 52, 8), (5, 87, 8, 52, 16), (5, 87, 8, 16, 52), (5, 87, 52, 8, 16), (5, 87, 52, 16, 8), (5, 87, 16, 8, 52), (5, 87, 16, 52, 8), (8, 5, 52, 16, 87), (8, 5, 52, 87, 16), (8, 5, 16, 52, 87), (8, 5, 16, 87, 52), (8, 5, 87, 52, 16), (8, 5, 87, 16, 52), (8, 52, 5, 16, 87), (8, 52, 5, 87, 16), (8, 52, 16, 5, 87), (8, 52, 16, 87, 5), (8, 52, 87, 5, 16), (8, 52, 87, 16, 5), (8, 16, 5, 52, 87), (8, 16, 5, 87, 52), (8, 16, 52, 5, 87), (8, 16, 52, 87, 5), (8, 16, 87, 5, 52), (8, 16, 87, 52, 5), (8, 87, 5, 52, 16), (8, 87, 5, 16, 52), (8, 87, 52, 5, 16), (8, 87, 52, 16, 5), (8, 87, 16, 5, 52), (8, 87, 16, 52, 5), (52, 5, 8, 16, 87), (52, 5, 8, 87, 16), (52, 5, 16, 8, 87), (52, 5, 16, 87, 8), (52, 5, 87, 8, 16), (52, 5, 87, 16, 8), (52, 8, 5, 16, 87), (52, 8, 5, 87, 16), (52, 8, 16, 5, 87), (52, 8, 16, 87, 5), (52, 8, 87, 5, 16), (52, 8, 87, 16, 5), (52, 16, 5, 8, 87), (52, 16, 5, 87, 8), (52, 16, 8, 5, 87), (52, 16, 8, 87, 5), (52, 16, 87, 5, 8), (52, 16, 87, 8, 5), (52, 87, 5, 8, 16), (52, 87, 5, 16, 8), (52, 87, 8, 5, 16), (52, 87, 8, 16, 5), (52, 87, 16, 5, 8), (52, 87, 16, 8, 5), (16, 5, 8, 52, 87), (16, 5, 8, 87, 52), (16, 5, 52, 8, 87), (16, 5, 52, 87, 8), (16, 5, 87, 8, 52), (16, 5, 87, 52, 8), (16, 8, 5, 52, 87), (16, 8, 5, 87, 52), (16, 8, 52, 5, 87), (16, 8, 52, 87, 5), (16, 8, 87, 5, 52), (16, 8, 87, 52, 5), (16, 52, 5, 8, 87), (16, 52, 5, 87, 8), (16, 52, 8, 5, 87), (16, 52, 8, 87, 5), (16, 52, 87, 5, 8), (16, 52, 87, 8, 5), (16, 87, 5, 8, 52), (16, 87, 5, 52, 8), (16, 87, 8, 5, 52), (16, 87, 8, 52, 5), (16, 87, 52, 5, 8), (16, 87, 52, 8, 5), (87, 5, 8, 52, 16), (87, 5, 8, 16, 52), (87, 5, 52, 8, 16), (87, 5, 52, 16, 8), (87, 5, 16, 8, 52), (87, 5, 16, 52, 8), (87, 8, 5, 52, 16), (87, 8, 5, 16, 52), (87, 8, 52, 5, 16), (87, 8, 52, 16, 5), (87, 8, 16, 5, 52), (87, 8, 16, 52, 5), (87, 52, 5, 8, 16), (87, 52, 5, 16, 8), (87, 52, 8, 5, 16), (87, 52, 8, 16, 5), (87, 52, 16, 5, 8), (87, 52, 16, 8, 5), (87, 16, 5, 8, 52), (87, 16, 5, 52, 8), (87, 16, 8, 5, 52), (87, 16, 8, 52, 5), (87, 16, 52, 5, 8), (87, 16, 52, 8, 5)]