from typing import Any, Dict, Iterable, Union def flatten( d: Union[Dict[str, Any], Dict[int, Any]], parent: str = "", sep: str = "." ) -> Dict[Union[str, int], Any]: """ Flatten dictionary keys. """ ret = {} for key, value in d.items(): new_key = str(sep.join([str(parent), str(key)]) if parent else key) if isinstance(value, dict): ret.update(flatten(value, new_key, sep=sep)) else: ret[new_key] = value return ret def exclude(d: Dict[str, Any], *, keys: Iterable[str]) -> Dict[str, Any]: return {i: d[i] for i in d if i not in keys}