Are You Using Python Function-Tools?

An underused library with important features

Dorel Masasa
The Startup

--

Photo by Doran Erickson on Unsplash

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!

Partial Functions

--

--

Dorel Masasa
The Startup

Senior Python Developer and Big Data Researcher, For Any Request/Question On a Topic, Feel Free To Mail — masasaMedium@gmail.com