I recently started learning functional programming and came up with this example, trying to calculate the average quiz for a class.
An example I came up with is:
scores = [90, 91, 92, 94, 95, 96, 97, 99, 100] def add(num1, num2): '''returns the sum of the parameters''' return num1 + num2 import operator timeit reduce(add, scores) / len(scores)
It would seem that in the above example, using a higher-order function is almost 4 times slower.
So my questions are, when would there be a good time to use a higher order function, because it is clear that the example above is not it?
python profiling functional-programming
Dor-ron
source share