def subdict(d, keys=None, nokeys=None):
    """Returns a subdictionary.

    Parameters
    ----------
    d : dict
        A dictionary.
    keys : list or set
        The set of keys to include in the subdictionary. If None use all keys.
    nokeys : list or set
        The set of keys to exclude from the subdictionary. If None no key is
        excluded.
    """
    keys = set(keys if keys else d.keys())
    nokeys = set(nokeys if nokeys else [])
    return {k: v for k, v in d.items() if k in (keys - nokeys)}