How to write function with variable from the outside?
问题 I hope you can help. I am looking for a way to write a function that inserts one item later. Let me show you an example: def general_poly(L): """ L, a list of numbers (n0, n1, n2, ... nk) Returns a function, which when applied to a value x, returns the value n0 * x^k + n1 * x^(k-1) + ... nk * x^0 """ x = 1 res = 0 n = len(L)-1 for e in range(len(L)): res += L[e]*x**n n -= 1 return res I thought I could just give x a value here and once I do general_poly(L)(10) it will be replaced so that x =