from typing import Dict
from typing import Any
from typing import Callable


def pop_if(jdict: Dict[str, Any], pred: Callable[[str, Any], bool]) -> Dict[str, Any]:
    """Pop a (key, value) pair based on predicate `pred`.

    Args:
        jdict: A dictionary
        pred: According to which the value is popped

    Returns:
        A :class:`dict` of popped values.

    """
    to_pop = []
    popped = {}
    for k, v in jdict.items():
        if pred(k, v):
            to_pop.append(k)
        if isinstance(v, dict):
            popped.update(pop_if(v, pred))
    for p in to_pop:
        popped.update(jdict.pop(p))
    return popped