def keep_keys(new_keys, old_dict):
    """Return dictionary with items indicated by the keys.

    Args:
        new_keys (iterable): Keys to keep from the old dictionary.
        old_dict (dict): A dictionary from which to extract a subset of items.

    Returns
        dict: A dict derived from old_dict only keeping keys from new_keys.

    Example:
        To use `keep_keys` directly on a dictionary:

        >>> keep_keys(["a", "b"], {"a": 1, "b": 2, "c": 3})
        {'a': 1, 'b': 2}

        If the requested keys are not present, they are ignored.

        >>> keep_keys(["a", "b"], {"b": 2, "c": 3})
        {'b': 2}

        To use `keep_keys` on a stream of dictionaries:

        >>> dict_gen = iter([{"a": 1, "b": 2, "c": 3},
        ...                  {"b": 5, "c": 6}])
        >>> from functools import partial
        >>> subdict_gen = map(partial(keep_keys, ["a", "b"]), dict_gen)
        >>> list(subdict_gen)
        [{'a': 1, 'b': 2}, {'b': 5}]
    """
    new_dict = {k: old_dict[k] for k in new_keys if k in old_dict}
    return new_dict