rllm.utils.remap_keys

class rllm.utils.remap_keys(inputs: Dict[X, Any], mapping: Dict[X, Y], exclude: List[X] | None = None)[source]

Bases:

Remap the keys of the input dictionary using a mapping.

Parameters:
  • inputs (Dict[X, Any]) – The input dictionary whose keys are to be remapped.

  • mapping (Dict[X, Y]) – A mapping from old keys to new keys.

  • exclude (List[X], optional) – Keys to leave unchanged even if present in mapping. (default: None)

Returns:

A new dictionary with remapped keys.

Return type:

Dict[Union[X, Y], Any]

Example

>>> inputs = {'a': 1, 'b': 2, 'c': 3}
>>> mapping = {'a': 'A', 'b': 'B'}
>>> remap_keys(inputs, mapping)
{'A': 1, 'B': 2, 'c': 3}