This is what I currently have and it works fine:
def iterate(seed, num):
x = seed
orbit = [x]
for i in ran
Just pass the function as a parameter. For instance:
def iterate(seed, num, func=lambda x: 2*x*(1-x)):
x = seed
orbit = [x]
for i in range(num):
x = func(x)
orbit.append(x)
return orbit
You can then either use it as you currently do or pass a function (that takes a single argument) eg:
iterate(3, 12, lambda x: x**2-3)
You can also pass existing (non lambda functions) in the same way:
def newFunc(x):
return x**2 - 3
iterate(3, 12, newFunc)