language: Python 3 (python-3.2.3)
date: 437 days 18 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
import itertools
line = ['A','B','%']
def line_permutations(line):
   if '%' not in line:
       return [line]
   line.remove('%') # use copy.copy if you don't want to modify your matrix here
   for i in range(len(line)):
       yield line[i:] + ['%'] + line[:i]
permutations = itertools.product([line_permutations(line) for line in matrix])
print(permutations)