list of polynomial functions

Josiah Manson slomojo83 at gmail.com
Thu Jun 15 12:49:00 EDT 2006


In the following program I am trying to learn how to use functional
programming aspects of python, but the following program will crash,
claiming that the recursion depth is too great. I am attempting to make
a list of polynomial functions such that poly[0](3) = 1, poly[1](3) =
3, poly[2](3) = 9, etc. Could someone point me in the right direction?
Thanks.

def make_polys(n):
	"""Make a list of polynomial functions up to order n.
	"""
	p = lambda x: 1
	polys = [p]

	for i in range(n):
		polys.append(lambda x: polys[i](x)*x)

	return polys

# construct a vector of polynomials
polys = make_polys(5)

# print
for p in polys:
	print p(3)




More information about the Python-list mailing list