Created
March 7, 2020 10:38
-
-
Save amalgjose/f724d3d6a0070284332902cebeb26562 to your computer and use it in GitHub Desktop.
Implementation of passing list of functions as an argument to another function in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import exp | |
def exec_func(function_list, p): | |
""" | |
This function passes the value p to each element in the function_list. | |
Each element in function_list is a function | |
---------- | |
function_list : a list of functions | |
p : operand | |
------- | |
output: The results will be stored in a list and will be the output of this main function | |
""" | |
output = [] | |
for function in function_list: | |
output.append(function(p)) | |
return output | |
if __name__ == '__main__': | |
sample_list = [str, abs,exp,int] | |
print(exec_func(sample_list, 10.0001)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment