How do I generate permutations of length LEN given a list of N Items?
Assuming you're in python 2.6 or newer:
from itertools import permutationsfor i in permutations(your_list, 3): print i
In case you need all combinations of a list with length n where n may be larger than the list elements, and also with repeated elements:
import itertoolslist(itertools.product([-1,1], repeat=3))
[(-1, -1, -1), (-1, -1, 1), (-1, 1, -1), (-1, 1, 1), (1, -1, -1), (1, -1, 1), (1, 1, -1), (1, 1, 1)]
imagine a cartesian product like [-1,1]x[-1,1]x[-1,1]