Nov-18-2017, 05:18 PM
I have the following list:
list = [['A', 'M'], ['G', 'R'], ['T', 'E']]
I want to find the number of permutations of these letters, such that a letter from a sublist can only be used once.
In this case there are 2 x 2 x 2 = 8 possible permutations, namely: AGT, AGE, ARE, ART, MGT, MGE, MRT, MRE.
Attempt
I have been trying to use the itertools.permutations function. This was my first try:
list = [['A', 'M'], ['G', 'R'], ['E', 'T']] pairs = [combo for combo in itertools.permutations(list, 3)] print pairs
Output:[(['A', 'M'], ['G', 'R'], ['E', 'T']), (['A', 'M'], ['E', 'T'], ['G', 'R']), (['G', 'R'], ['A', 'M'], ['E', 'T']), (['G', 'R'], ['E', 'T'], ['A', 'M']), (['E', 'T'], ['A', 'M'], ['G', 'R']), (['E', 'T'], ['G', 'R'], ['A', 'M'])]
As you can see, this is finding the number of permutations of the 3 sublists, which is not what I want. Any ideas?
I want my output to look something like:
Output:[['A', 'G', 'E'], ['A', 'R', 'E'], ... ]