Ask Your Question

# Revision history [back]

I think you're going to be interested in list comprehensions and generator expressions.

Using listcomps, your code compresses to:

sage: funclist = [1/x^i for i in range(10)]
sage: plotlist = [f.plot((x, 1, 10), ymax=5) for f in funclist]
sage: plot(plotlist)


(Note that I changed the x lower limit to make it look better.) [BTW, as for your ability to use "a += something", that was almost certainly because you already had an "a" floating around from before.]

I think you're going to be interested in list comprehensions and generator expressions.

Using listcomps, your code compresses to:

sage: funclist = [1/x^i for i in range(10)]
sage: plotlist = [f.plot((x, 1, 10), ymax=5) for f in funclist]
sage: plot(plotlist)


(Note that I changed the x lower limit to make it look better.) [BTW, as for your ability to use "a += something", that was almost certainly because you already had an "a" floating around from before.]

If you want to one-line it:

plot([(1/x^i).plot((x, 1, 10), ymax=5) for i in range(10)])


I think you're going to be interested in list comprehensions and generator expressions.

Using listcomps, your code compresses to:

sage: funclist = [1/x^i for i in range(10)]
sage: plotlist = [f.plot((x, 1, 10), ymax=5) 10)) for f in funclist]
sage: plot(plotlist)


(Note that I changed the x lower limit to make it look better.) [BTW, as for your ability to use "a += something", that was almost certainly because you already had an "a" floating around from before.]

If you want to one-line it:

plot([(1/x^i).plot((x, 1, 10), ymax=5) 10)) for i in range(10)])