Thanks guys! Exactly what I needed, :-)
Hopefully when I get better at this stuff, I can come back here and contribute.
User Profile
Collapse
-
Okay, sorry about that... so say if I put in:
repeatedlyApply (lambda x: 2*x,3)("abc")
I should get: 'abcabcabcabcab cabcabcabc'
or repeatedlyApply (lambda x: x+1,10)(100)
should yield 110
The first argument I pass is a function with one argument of its own (In the first case "abc" and in the second "100") and the second is the number of times to...Leave a comment:
-
-
Python Help -- Apply a procedure repeatedly
Hi, I'm trying to write a function that takes in as arguments a procedure with one argument and an integer. The integer represents how many times the procedure will execute on the argument.
...Code:def compose(f,g): return lambda x: f(g(x)) def repeatedlyApply (p,n): i=0 q=0 while (i<n): q = compose(p,p) i=i+2 return q
No activity results to display
Show More
Leave a comment: