It's been a while, so just answering this is probably fine.
First, let's rewrite your example, so it's actually real code:
First, let's rewrite your example, so it's actually real code:
def iterate(numberofiterations,initial): f = lambda x: 2*x count = srange(numberofiterations) vals = [initial] for i in count: a = vals[i] b = f(a) vals.append(b) return valsOk, now let's rewrite it again, so the function can be passed in:
def iterate(mutator, numberofiterations, initial): count = srange(numberofiterations) vals = [initial] for i in count: a = vals[i] b = mutator(a) vals.append(b) return valsAlso, for the love of Guido, please use variable names with more than one character.
a
and b
is incredibly ridiculous, and you should feel bad for using those.