def dict_convert(_dict, keyfn=None, valuefn=None):
    """Return a new dict with each key converted by keyfn (if not None),
       and each value converted by valuefn (if not None).
    """
    if keyfn is None and valuefn is not None:
        for k in _dict:
            _dict[k] = valuefn(_dict[k])
        return _dict
    elif keyfn is not None:
        out_dict = {}
        for k in _dict:
            out_dict[keyfn(k)] = valuefn(_dict[k]) if valuefn else _dict[k]
        return out_dict
    else:
        return _dict
