Hey I have a list where I would want to get all the different permutations of it i.e [A,B,C].

I want all different combinations of it. like so [A,C,B], [B,A,C], [B,A,C], [C,A,B] and [C,B,A] i tried using itertools.combinations and I get all combinations just not the ones with all letters in use.

matriks = ["A","B","C"]
    for i in xrange(1, len(matriks)+1):
    els = [list(x) for x in itertools.combinations(matriks, i)]

this gives the following output

[[['A'], ['B'], ['C']], [['A', 'B'], ['A', 'C'], ['B', 'C']], [['A', 'B', 'C']]]
  • 1
    "combinations" and "permutations" are different things. Sounds like you want the latter. – Wooble Jan 13 '14 at 15:12
  • yes did not know the word. Permutations is what i wanted – Becktor Jan 13 '14 at 15:19

You can simply use itertools.permutations:

>>> from itertools import permutations
>>> l = ["A","B","C"]
>>> list(permutations(l))
[('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]
