from math import cos
def gsecant(fun, x0, x1):
f0, f1 = fun(x0), fun(x1)
while True:
x_new = x1 - f1 * (x1 - x0) / (f1 - f0)
x0, x1 = x1, x_new
f0, f1 = f1, fun(x1)
yield x1
s = gsecant(lambda x: cos(x) - x, 2, 3)
print([s.next() for i in range(7)])