def step_fn(step_dict):
    """
    Create a step function from a dictionary.

    Parameters
    ----------
    step_dict           : dict
                          Dictionary of cut-offs and weight values.

    Returns
    -------

    weight_function     : function
                          Function returning weight, for input distance or time, *x*.
                          Values beyond the largest threshold will return 0.

    Examples
    --------

    Import the weights:

    >>> from access import weights

    Create a step function with thresholds at 20, 40, and 60.
    Travel costs are in minutes here, but the code cannot tell if you mix units!

    >>> fn = weights.step_fn({20 : 1, 40 : 0.68, 60 : 0.22})

    >>> {v : fn(v) for v in range(0, 71, 10)}
    {0: 1, 10: 1, 20: 1, 30: 0.68, 40: 0.68, 50: 0.22, 60: 0.22, 70: 0}
    """

    if type(step_dict) != dict:
        raise TypeError('step_dict must be of type dict.')

    for v in step_dict.values():
        if v < 0:
            raise ValueError('All weights must be positive.')

    def helper(key_to_test):

        for k,v in sorted(step_dict.items()):
            if key_to_test <= k:
                return v

        return 0

    return helper