Posts

Showing posts with the label functional

Promising Power: functools and itertools of Python

I worked through functools and itertools sections of the Computational Statistics in Python tutorial , and I found these promisingly powerfuul for data modeling and functional programming: # The functools module """The most useful function in the functools module is partial, which allows you to create a new function from an old one with some arguments “filled-in”.""" from functools import partial def power_function(power, num): """power of num.""" return num**power square = partial(power_function, 2) cube = partial(power_function, 3) quad = partial(power_function, 4) # The itertools module """This provides many essential functions for working with iterators. The permuations and combinations generators may be particularly useful for simulations, and the groupby gnerator is useful for data analyiss.""" from itertools import cyc...