def product_sequence(xs):
x = Symbol('x')
y = 1
res = []
for item in xs:
y *= x - item
res.append(y)
return res
Or, more elegant using yield
:
def product_gen(xs):
x = Symbol('x')
y = 1
for item in xs:
y *= x - item
yield y
res = list(product_gen(xs))