So I have written a function f(a, b). The structure is:
def f(a, b):
global result
def g(a, b):
global result
return result
deg h(a):
return a # an updated a
g(a, b)
a = h(a)
g(a, b)
a = h(a)
g(a, b)
a = h(a)
g(a, b)
return result
- You can see that I have two sub-functions
g(a, b)andh(a)inf(a, b). - I need to run
g(a, b)to get the partial result - Then I updated the
a - So that I can run
g(a, b)again, to update the result. - After 4 runs of
g(a, b), I got the full piece of result and return the value.
There must be a way to structure the process here that looks simpler and clearer.
I also tried:
g(a, b)
g(h(a), b)
g(h(h(a), b)
g(h(h(h(a), b)
And that looks hideous as well.
I need some suggestion to simply to structure here, maybe to use the map() or other high order functions? But I just couldn't figure it out.
Thanks!
mapworks on lists - it has nothing to do with high-order functionsglobal result? And why aren't you saving the value returned by thegfunction? And why doesn'tgdo anything with the arguments you pass it?