Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Composition/functools: three uses of itertools, one counter solution in Creative category for Aggregate and Count by Phil15
import itertools as it
from collections import Counter
from functools import partial
# Some basic function to apply multiple functions.
def compose(*funcs):
def wrapper(*args, **kwargs):
fs = reversed(funcs)
res = next(fs)(*args, **kwargs)
for f in fs:
res = f(res)
return res
return wrapper
aggregate_and_count = compose(
Counter,
it.chain.from_iterable,
partial(it.starmap, it.repeat),
)
July 17, 2021