I have a list of intended function names e.g. ['check_one', 'check_two', 'check_three']
and would like to create Python functions using them as function names.
The following doesn't work:
for func_name in ['check_one', 'check_two', 'check_three']:
def f'{func_name}'(text):
print(text)
The intended effect is that I have three functions defined as follows:
check_one('one fine day') # This function checks for the presence of the exact word
# 'one' in the argument. It should return integer 1 if True,
# and 0 if False. An example of a False result would be 'oneone fine day'.
check_two('hello world') # Likewise, this function checks for the presence of the word
# 'two' in the argument. In this case, it should return a 0.
check_three('c') # Likewise
My original function is:
def check_one(string):
return int((' ' + 'one' + ' ') in (' ' + string + ' '))
So I'd like a way to generate these functions through a loop, by providing a list of function names ['check_one', 'check_two', 'check_three'].
Would appreciate any help. Thank you!