Python Lecture 16-High Order Function
Python Lecture 16-High Order Function
Lamda Function
• Function without name (anonymous)
• Lambda functions can only be comprised of
a single expression
– No loops, no calling other methods
– Lambda functions can take any number of
variables
• Syntax:
lambda param1,…,paramn : expression
Exmples
False
56
Higher Order Function
• A higher-order function is a function that takes
another function as a parameter
• They are “higher-order” because it’s a function of a
function
• Examples
– Map
– Reduce
– Filter
• Lambda can work as a parameter to higher-order
functions
Higher Order Function
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
Higher Order Function
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
Higher Order Function
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
map function
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
map function
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
map function
https://www.southampton.ac.uk/~fangohr/training/python/pdfs/Python-for-Computational-Science-and-Engineering.pdf
map function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
map function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
reduce function
Reduce takes a binary function and a list, and
returns a single value, which is obtained by
repeatedly applying the binary function to pairs
of elements in the list.
source: https://courses.csail.mit.edu/6.01/spring08/handouts/week2/lecture-handout-week-2.pdf
reduce function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
reduce function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
reduce function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
filter function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf
filter function
source: https://courses.cs.washington.edu/courses/cse143/10wi/python/3/python143_lecture2.pdf