I learned a tricks to pass functions as argument
def remove_punctuation(value):
return re.sub('[!#?]', '', value)
clean_ops = [str.strip, remove_punctuation, str.title]
def clean_strings(strings, ops):
result = []
for value in strings:
for function in ops:
value = function(value)
result.append(value)
return result
print(clean_strings(states, clean_ops))
I find it amazing to encapsulate required functions to a list which even helps in the thinking process.
What's the pattern of the such a practice?