target: | https://readthedocs.org/projects/fntools/?badge=master |
---|---|
alt: | Documentation Status |
fntools provides functional programming tools for data processing. This module is a set of functions that I needed in my work and found useful.
pip install fntools
Split a list of elements with factors with split:
songs = ('Black', 'Even Flow', 'Amongst the waves', 'Sirens') albums = ('Ten', 'Ten', 'Backspacer', 'Lightning Bolt') print split(songs, albums) {'Lightning Bolt': ['Sirens'], 'Ten': ['Black', 'Even Flow'], 'Backspacer': ['Amongst the waves']}
Determine whether any element of a list is included in another list with any_in:
print any_in(['Oceans', 'Big Wave'], ['Once', 'Alive', 'Oceans', 'Release']) True print any_in(['Better Man'], ['Man of the Hour', 'Thumbing my way']) False
Apply many functions on the data with dispatch:
# Suppose we want to know the mean, the standard deviation and the median of # a distribution (here we use the standard normal distribution) import numpy as np np.random.seed(10) x = np.random.randn(10000) print dispatch(x, (np.mean, np.std, np.median)) [0.0051020560019149385, 0.98966401277169491, 0.013111308495186252]
Many more useful functions are available. For more details, go to the documentation.
- The excellent toolz by Matthew Rocklin
- A pratical introduction to functional programming by Mary Rose Cook
- A bit of R (multimap, use, use_with)