0% found this document useful (0 votes)
16 views20 pages

Python Higher-Order Functions Guide

The document discusses high-order functions in Python, focusing on lambda functions, which are anonymous and consist of a single expression. It explains higher-order functions, such as map, reduce, and filter, which take other functions as parameters, and provides a brief overview of how the map and reduce functions operate. Additionally, it highlights that lambda functions can be used as parameters in these higher-order functions.

Uploaded by

Abhishek Goutam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views20 pages

Python Higher-Order Functions Guide

The document discusses high-order functions in Python, focusing on lambda functions, which are anonymous and consist of a single expression. It explains higher-order functions, such as map, reduce, and filter, which take other functions as parameters, and provides a brief overview of how the map and reduce functions operate. Additionally, it highlights that lambda functions can be used as parameters in these higher-order functions.

Uploaded by

Abhishek Goutam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python: High Order Functions

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: [Link]
Higher Order Function

source: [Link]
Higher Order Function

source: [Link]
map function

map(function, iterable, ...)

• Map applies function to each element of


iterable (sequence/list) and creates a list of the
results
map function

source: [Link]
map function

source: [Link]
map function

[Link]
map function

source: [Link]
map function

source: [Link]
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.

So, if the list contains elements x1,x2,…xn and


the function is f then the result will be
f(...f(f(x1,x2),x3),...xn)
reduce function

source: [Link]
reduce function

source: [Link]
reduce function

source: [Link]
reduce function

source: [Link]
filter function

source: [Link]
filter function

source: [Link]

You might also like