# Revision history [back]

You can use the words of length $n$ over the alphabet $\{-1,1\}$:

sage: n = 4
sage: W = Words(length=n, alphabet=[-1,1])
sage: W
Words of length 4 over {-1, 1}
sage: L = [tuple(w) for w in W]
sage: L
[(-1, -1, -1, -1),
(-1, -1, -1, 1),
(-1, -1, 1, -1),
(-1, -1, 1, 1),
(-1, 1, -1, -1),
(-1, 1, -1, 1),
(-1, 1, 1, -1),
(-1, 1, 1, 1),
(1, -1, -1, -1),
(1, -1, -1, 1),
(1, -1, 1, -1),
(1, -1, 1, 1),
(1, 1, -1, -1),
(1, 1, -1, 1),
(1, 1, 1, -1),
(1, 1, 1, 1)]


You can use the words of length $n$ over the alphabet $\{-1,1\}$:$\{-1,1\}$, and the transform each of them into a tuple:

sage: n = 4
sage: W = Words(length=n, alphabet=[-1,1])
sage: W
Words of length 4 over {-1, 1}
sage: L = [tuple(w) for w in W]
sage: L
[(-1, -1, -1, -1),
(-1, -1, -1, 1),
(-1, -1, 1, -1),
(-1, -1, 1, 1),
(-1, 1, -1, -1),
(-1, 1, -1, 1),
(-1, 1, 1, -1),
(-1, 1, 1, 1),
(1, -1, -1, -1),
(1, -1, -1, 1),
(1, -1, 1, -1),
(1, -1, 1, 1),
(1, 1, -1, -1),
(1, 1, -1, 1),
(1, 1, 1, -1),
(1, 1, 1, 1)]


You can use the words of length $n$ over the alphabet $\{-1,1\}$, and the transform each of them into a tuple:

sage: n = 4
sage: W = Words(length=n, alphabet=[-1,1])
sage: W
Words of length 4 over {-1, 1}
sage: L = [tuple(w) for w in W]
sage: L
[(-1, -1, -1, -1),
(-1, -1, -1, 1),
(-1, -1, 1, -1),
(-1, -1, 1, 1),
(-1, 1, -1, -1),
(-1, 1, -1, 1),
(-1, 1, 1, -1),
(-1, 1, 1, 1),
(1, -1, -1, -1),
(1, -1, -1, 1),
(1, -1, 1, -1),
(1, -1, 1, 1),
(1, 1, -1, -1),
(1, 1, -1, 1),
(1, 1, 1, -1),
(1, 1, 1, 1)]


If $n$ is large and you want to save memory, you can creat an iterator instead of a list, by writing, instead of L:

sage: It = (tuple(w) for w in W)
sage: for i in It:
....:     print i
....:
(-1, -1, -1, -1)
(-1, -1, -1, 1)
(-1, -1, 1, -1)
(-1, -1, 1, 1)
(-1, 1, -1, -1)
(-1, 1, -1, 1)
(-1, 1, 1, -1)
(-1, 1, 1, 1)
(1, -1, -1, -1)
(1, -1, -1, 1)
(1, -1, 1, -1)
(1, -1, 1, 1)
(1, 1, -1, -1)
(1, 1, -1, 1)
(1, 1, 1, -1)
(1, 1, 1, 1)


You can also use the cartesian products:

sage: A = cartesian_product_iterator([[-1,1] for i in range(n)])
sage: for i in A:
....:     print i
....:
(-1, -1, -1, -1)
(-1, -1, -1, 1)
(-1, -1, 1, -1)
(-1, -1, 1, 1)
(-1, 1, -1, -1)
(-1, 1, -1, 1)
(-1, 1, 1, -1)
(-1, 1, 1, 1)
(1, -1, -1, -1)
(1, -1, -1, 1)
(1, -1, 1, -1)
(1, -1, 1, 1)
(1, 1, -1, -1)
(1, 1, -1, 1)
(1, 1, 1, -1)
(1, 1, 1, 1)