Are You Using Python Function-Tools?
An underused library with important features
What Can Functools (Function-tools) do for us?
The STL library “functools” have great features, allow us to modify our function, with little to no code, and add functionality to them.
This all results in cleaner, more effective code that is easy to understand, monitor, and review. So without farther ado, let us get started!
Reduce
Reduce takes a function of 2 arguments, and an iterable.
And act cumulatively on the entire iterable!
For example, if we take a function that adds to numbers, using “reduce,” we could sum up every list we want! Or concatenate strings!
This method could come in handy in custom functions that want to implement on a list of items, if its unique multiplication, or special object operations!