Re: Can you pass functions as arguments?

2005-12-19 Thread Xavier Morel
[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

Re: Can you pass functions as arguments?

2005-12-19 Thread Bengt Richter
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

Re: Can you pass functions as arguments?

2005-12-19 Thread Paul Rubin
[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

Can you pass functions as arguments?

2005-12-18 Thread bobueland
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

Re: Can you pass functions as arguments?

2005-12-18 Thread Paul Rubin
[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