I want to iterate over all the vertices of an n
dimensional cube of size 1. I know I could do that with itertools.product
as follows:
&
If you've written more than eight lines of code to generate eight constant values, something has gone wrong.
Short of just embedding the list I want, I'd do it the dumb way:
vertices = (
(v.count(1), v)
for v in itertools.product((0, 1), repeat=3)
)
for count, vertex in sorted(vertices):
print vertex
Unless you're working with 1000-hypercubes, you shouldn't have any huge performance worries.