March 20, 2010
12:21 a.m.
On Fri, Mar 19, 2010 at 8:17 AM, Joe Kington <jkington@wisc.edu> wrote:
See itertools.permutations (python standard library) e.g. In [3]: list(itertools.permutations([1,1,0,0])) Out[3]: [(1, 1, 0, 0), (1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 0, 1), (1, 1, 0, 0), (1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 0, 1), (0, 1, 1, 0), (0, 1, 0, 1), (0, 1, 1, 0), (0, 1, 0, 1), (0, 0, 1, 1), (0, 0, 1, 1), (0, 1, 1, 0), (0, 1, 0, 1), (0, 1, 1, 0), (0, 1, 0, 1),
(0, 0, 1, 1), (0, 0, 1, 1)] Hope that helps, -Joe
That treats each 1 as distinct. set() solves that:
list(set(itertools.permutations([1,1,0,0])))
[(1, 0, 1, 0), (1, 1, 0, 0), (0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 1, 0), (0, 1, 0, 1)]