def keepkeys(d, keys):
    """Drop all keys from dictionary ``d`` except those in
    ``keys``. Modifies the dictionary in place!
    
    :param d: The dictionary to modify
    :type d: dict

    :param keys: The keys to keep
    :type keys: iterable
    """

    ks = set(list(keys))
    to_rm = [k for k in d.keys() if k not in ks]
    for k in to_rm:
        del d[k]
    return d