Ask Your Question

Revision history [back]

I guess your problem comes the iterated loops that you can not write one by one since you do ont know a priori how many loops there will be (it depends on the number of variables). To solve this issue, you can have a look at itertools.product:

sage: from itertools import product
sage: product?

Then you can do something like (i just give some hints about zip and dictionaries):

sage: for I in product(*[range(f.degree(v), -1, -1) for v in P.gens()]):
sage:     print I
sage:     print dict(zip(P.gens(),I))