def subDict(d, allowedkeys, flip=False):
    """ Returns a new dictionary with a subset of the entries of d
    that have on of the (dis-)allowed keys."""
    res = {}
    for k, v in d.items():
        if (k in allowedkeys) ^ flip:
            res[k] = v
    return res
