from typing import MutableMapping
from typing import Any
from typing import Dict


def pop_by_prefix(
    d: MutableMapping[str, Any], key_prefix: str) -> Dict[str, Any]:
  """Returns {k: v for key_prefix+k, v in d.items()} and removes them from d."""
  popped = {}
  for key in list(d.keys()):
    if key.startswith(key_prefix):
      popped[key[len(key_prefix):]] = d.pop(key)
  return popped