Ask Your Question

Revision history [back]

You can use words:

sage: W = Words(alphabet='01', length=15)
sage: W
Words of length 15 over {'0', '1'}

Then you can iterate over them, and access the i^th bit as follows:

sage: for w in W:
....:    print w, w[2]

If you want you bits to be integers, not strings, you can do:

sage: W = Words(alphabet=[0,1], length=15)
sage: W
Words of length 15 over {0, 1}

You can use words:

sage: W = Words(alphabet='01', length=15)
sage: W
Words of length 15 over {'0', '1'}

Then you can iterate over them, and access the i^th bit as follows:

sage: for w in W:
....:    print w, w[2]

If you want you bits to be integers, not strings, you can do:

sage: W = Words(alphabet=[0,1], length=15)
sage: W
Words of length 15 over {0, 1}

If you want to use only Python (not sage Words), you can use the itertools module:

sage: import itertools
sage: W = itertools.product([0,1], repeat=15)
sage: for w in W:
....:    print w, w[2]

You can use words:

sage: W = Words(alphabet='01', length=15)
sage: W
Words of length 15 over {'0', '1'}

Then you can iterate over them, and access the i^th bit as follows:

sage: for w in W:
....:     print w, w[2]

If you want you bits to be integers, not strings, you can do:

sage: W = Words(alphabet=[0,1], length=15)
sage: W
Words of length 15 over {0, 1}

If you want to use only Python (not sage Words), you can use the itertools module:

sage: import itertools
sage: W = itertools.product([0,1], repeat=15)
sage: for w in W:
....:     print w, w[2]

You can use words:

sage: W = Words(alphabet='01', length=15)
sage: W
Words of length 15 over {'0', '1'}

Then you can iterate over them, and access the i^th bit as follows:

sage: for w in W:
....:     print w, w[2]

If you want you bits to be integers, not strings, you can do:

sage: W = Words(alphabet=[0,1], length=15)
sage: W
Words of length 15 over {0, 1}

If you want to use only Python (not sage Words), you can use the itertools module:

sage: import itertools
sage: W = itertools.product([0,1], repeat=15)
sage: for w in W:
....:     print w, w[2]