toolz

1.1.0 · maintenance · verified Sat Mar 28

toolz is a Python library providing a collection of utility functions for iterators, functions, and dictionaries, extending Python's standard `itertools` and `functools`. It promotes a functional programming style with features like composable, pure, and lazy operations. The current version is 1.1.0, and while the project is alive and maintained for critical bug fixes and Python version bumps, it is generally considered 'inactive' by its maintainers, who view it as mostly complete.

Warnings

Install

Imports

Quickstart

This example demonstrates how to build a word counting function using `compose`, `frequencies`, and the curried `map` from `toolz` to process a sentence.

from toolz import compose, frequencies
from toolz.curried import map

def stem(word):
    """ Stem word to primitive form """
    return word.lower().rstrip(",.!:;'-\"").lstrip("'\"")

wordcount = compose(frequencies, map(stem), str.split)
sentence = "This cat jumped over this other cat!"
result = wordcount(sentence)

print(result)
# Expected: {'this': 2, 'cat': 2, 'jumped': 1, 'over': 1, 'other': 1}

view raw JSON →