Ask Your Question

Revision history [back]

You can use R.gen(i-1), but it takes fewer keystrokes to slice the list of generators:

sage: g = 3; n = 4
sage: R = PolynomialRing(QQ, ['lambda%s'%i for i in [1 .. g]] + ['psi%s'%i for i in [1 .. n]])
sage: lambdas = R.gens()[:g]
sage: psis = R.gens()[n-1:]
sage: lambdas, psis
((lambda1, lambda2, lambda3), (psi1, psi2, psi3, psi4))

Another trick is to start your indexing at 0 so that you can name your list like psi and then psi[0] will refer to the variable named psi0. Or you can shift your list, or make a dictionary, if you want indices to start at 1.