[EMAIL PROTECTED] wrote:
I want to calculate f(0) + f(1) + ...+ f(100) over some function f
which I can change. So I would like to create a function taking f as
argument giving back the sum. How do you do that in Python?
Python functions (and classes, and modules) are first-class objects, so
On 18 Dec 2005 23:18:48 -0800, Paul Rubin http://[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] writes:
I want to calculate f(0) + f(1) + ...+ f(100) over some function f
which I can change. So I would like to create a function taking f as
argument giving back the sum. How do you do that in
[EMAIL PROTECTED] (Bengt Richter) writes:
or if the OP actually wants the specific function,
def sum100a(f): return sum(imap(f, xrange(101)))
...
sum100a(square)
338350
Similarly with generator comprehension, if I have the syntax right:
def sum100c(f): return sum(f(i) for i in
I want to calculate f(0) + f(1) + ...+ f(100) over some function f
which I can change. So I would like to create a function taking f as
argument giving back the sum. How do you do that in Python?
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] writes:
I want to calculate f(0) + f(1) + ...+ f(100) over some function f
which I can change. So I would like to create a function taking f as
argument giving back the sum. How do you do that in Python?
You can just pass f as an argument. The following is not the most