Higher Order Functions with Python - sorted/map/filter/reduce and friends

preview_player
Показать описание
A quick overview for students in my online class: higher order functions are functions that take and return values which happen to be functions. In order to sort things in Python you need to know about key-functions which you pass to the builtin sorted - but you might also check out map, filter, reduce, min, max and so on. You can also use functional closures to produce custom functions from functions - and understanding this concept can lead to all sorts of interesting techniques.

Рекомендации по теме
Комментарии
Автор

My face just lit up!
"I see clearly now"
Thank you for an excellent tutorial.

HenockTesfaye
Автор

Thank-you, sir! you just saved me oodles of time. If only I'd seen this sooner.

IAMZERG
Автор

In Python 3.x reduce is part of functools. import functools; functools.reduce(...)

__nicfit__
Автор

Good point! I'm teaching a class on 2.7 so I didn't think to mention it...

SimeonFranklin
Автор

Hey, nice tutorial, but the last thing I didn't get. Why I need the closure for sorting if I could use a simple lambda or function instead?
sorted(["howard", "ray", "sheldon", "lenard"], key: lambda x: x[-2])
Is there an example of closures where I really need use them instead of alternative ways?

Pterryreal
Автор

Thank you for this wonderful video and your time..great job!

sidzie