def to_dict(key_func, value_func):
    """
    Returns a function which returns a dictionary by collecting the
    given iterable by key_func and value_func.  
    """
    def dict_collector(iterable):
        return {key_func(item): value_func(item) for item in iterable}
    return dict_collector