| 1 | initial version |
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))
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.