[Tutor] Higher-Order Function Examples
Steven D'Aprano
steve at pearwood.info
Mon Feb 14 12:35:48 CET 2011
Steven D'Aprano wrote:
> An example might help. Back in the old days, before Python had a sum()
> function, the easiest way to add up a list of numbers was to use reduce
> and a small function to add two numbers:
>
> def add(x, y):
> return x+y
>
> total = filter(add, [2, 4, 5, 9, 1])
Arggggh! Of course, I meant *reduce* in that example, not filter. Sorry
for any confusion!
--
Steven
More information about the Tutor
mailing list