def memoize(f):
    """ Cache function results, similar to py3.7 functools.lru_cache """
    memo = {}
    def helper(*args):
        key = tuple(args)
        if key not in memo:
            memo[key] = f(*args)
        return memo[key]
    return helper