libb.mapvals

mapvals(func, dct)[source]

Apply a function to all values in a dictionary.

Parameters:
  • func – Function to apply to each value.

  • dct (dict) – Dictionary to transform.

Returns:

New dictionary with transformed values.

Return type:

dict

Example:

>>> mapvals(lambda x: x * 2, {'a': 1, 'b': 2})
{'a': 2, 'b': 4}