云栖运营小编~
内置filter函数视为None始终返回的“函数” True。
from functors import partial
from operators import lt, gt
def filter_dates(x, lower_bound=None, upper_bound=None):
lb = None if lower_bound is None else partial(lt, lower_bound)
ub = None if upper_bound is None else partial(gt, upper_bound)
return filter(lb, filter(ub, x))
(请注意,这将适用于字符串或date对象;只需传递相应类型的下限和上限。)