SD2201-ch7-Higher Order Functions
SD2201-ch7-Higher Order Functions
01 02
A function That:
1. Is a First Class
2. Takes a function as an Argument
3. And / Or Return a function as Results
Remember the term First Class?
A first-class function is one that can go anywhere that any other value can go.
X : X * 10
1 10
4 40
5 50
L L’
How to Use ?
L = [1,2,3,4,5]
We can also use map with built in python function like abs, len ,int , str
Try this:
map( abs , [-1,2,3,5,-6] )
map( len , [ range(2) , range(3) , range(4) ] )
Map with multiple iterables
L1 = [1,2,3,4,5]
L2 = [ 2,2,3,3,2]
Map ( pow , L1 , L2 )
Consideration
For example we have pow() function which has 2 arguments the base and the
exponent.
2. Terdapat bilangan B
B = 24
B’ = [ 1,2,3,4,6,8,12,24]
Latihan
A = [ [3 , 4] , [ 5, 6 ] ]
B = [ [1,2] , [ 7 , 8] ]
C = AB