[Numpy-discussion] lists of zeros and ones

Gökhan Sever gokhansever at gmail.com
Fri Mar 19 11:21:56 EDT 2010

```On Fri, Mar 19, 2010 at 10:17 AM, Joe Kington <jkington at 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
>
>

If you use "set" you automatically eliminate replicates:

a = set(permutations([0,0,1,1]))

a
set([(0, 0, 1, 1),
(0, 1, 0, 1),
(0, 1, 1, 0),
(1, 0, 0, 1),
(1, 0, 1, 0),
(1, 1, 0, 0)])

Converting back to a list:

b = list(a)
--
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100319/e5bb2d09/attachment.html>
```