跳转至
本文阅读量

1. Python 函数式编程

1.1 functools 解释

功能 解释
@functools.cache(user_function)
@functools.cached_property(func)
functools.cmp_to_key(func)
@functools.lru_cache(user_function)
@functools.lru_cache(maxsize=128, typed=False)
@functools.total_ordering
functools.partial(func, /, *args, **keywords)
class functools.partialmethod(func, /, *args, **keywords)
functools.reduce(function, iterable[, initializer])¶
@functools.singledispatch
class functools.singledispatchmethod(func)
functools.update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)
@functools.wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)¶

1.2 itertools 解释

功能 解释
itertools.accumulate(iterable[, function, *, initial=None])
itertools.batched(iterable, n)
itertools.chain(*iterables)
classmethod chain.from_iterable(iterable)
itertools.combinations(iterable, r)
itertools.combinations_with_replacement(iterable, r)
itertools.compress(data, selectors)
itertools.count(start=0, step=1)
itertools.cycle(iterable)
itertools.dropwhile(predicate, iterable)
itertools.filterfalse(predicate, iterable)
itertools.groupby(iterable, key=None)
itertools.islice(iterable, stop)
itertools.islice(iterable, start, stop[, step])
itertools.pairwise(iterable)
itertools.permutations(iterable, r=None)
itertools.product(*iterables, repeat=1)
itertools.repeat(object[, times])
itertools.starmap(function, iterable)
itertools.takewhile(predicate, iterable)
itertools.tee(iterable, n=2)
itertools.zip_longest(*iterables, fillvalue=None)