Let's learn Higher Order Functions!
Drag and drop the options to the blanks to complete the program to form a function that takes in a function as parameter.
The goal of this function will be to take a list of strings, a string function and a list function as arguments.
Then it will apply the string function to each string in the list and apply the list function to the whole list.
Input = ['hello', 'this', 'is', 'a', 'list']
Output = ['A', 'HELLO', 'IS', 'LIST', 'THIS']
Complete the program
>>> def HigherOrderFunction(list, stringFunc, listFunc): for i in range(len(list)): list[i] =
return
>>> input = ["hello", "this","is", "a", "list"] >>> output = HigherOrderFunction(input,
,
) >>> print(output)
stringFunc(list[i])
str.upper
list.sort
listFunc(list)
lambda x: sorted(x)
list[i].stringFunc()
Observations(Without Higher Order Functions)
Without Higher-Order Functions this same application would have either had a separate function or would have taken two steps to complete.
Observations(With Higher Order Functions)
With Higher Order Functions, this function can do the thing in one step and also promotes modular code as you can use it for other purposes as well.