[Tutor] Higher-Order Function Examples

Rafael Durán Castañeda rafadurancastaneda at gmail.com
Mon Feb 14 20:16:02 CET 2011


Could we consider sorted as an high order function?

sorted_list = sorted(list_strings, key = str.lower)

2011/2/14 Steven D'Aprano <steve at pearwood.info>

> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110214/db194d56/attachment.html>


More information about the Tutor mailing list