def dict_factory(name, default):
    """Return a subclass of dict with a default value

    :param name: name of the subclass
    :type name: string
    :param default: the default value returned by the dict instead of KeyError
    """
    def __missing__(self, key):
        return default
    new_class = type(name, (dict,), {"__missing__": __missing__})
    return new_class