# polynomial list, array

I would like to store polynomials in an array/list in Sage. How do I do this?

I am editing my question due to the confusion expressed below.

I would like to generate a list of polynomials from a loop.

edit retag close merge delete

Thanks for the answers posted above. Though not directly resolving my intended question due to the confusing statement of my original post, they made me realize I need to declare the list first, like p = [], just like in Python, then append the polynomials or anything else for that matter, one by one, with say p.append(polynomial).

Sort by » oldest newest most voted

By making a list of polynomials?

sage: R.<t> = QQ[]
sage: L = [t^2+1, t^3+1, t^4+t^2-5]
sage: type(L)
<type 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>


Here I assume you mean real polynomials, and not symbolic expressions that happen to be polynomials, like

sage: x^2+1
x^2 + 1
sage: type(_)
<type 'sage.symbolic.expression.Expression'>

more

But maybe you meant:

sage: R.<x> = ZZ[]
sage: f = R.random_element(); f
-10*x^5 + 2*x^4 + 6*x^3 + x^2 + x + 4
sage: f.list()
[4, 1, 1, 6, 2, -10]


or

sage: list(f)
[4, 1, 1, 6, 2, -10]

more