Invert-a-dict

A dictionary is said to be invertible if all keys are associated to a
different value (and thus, each value happens only once).

Program a function inverse(d) that given an invertible dictionary d with
string keys and int values, returns its inverse. That is, a dictionary
where each int value in the original dictionary is now a key, and its
string key in the original dictionary is now its associated value.

For instance, if the original dictionary d is:

    { 'hello' : 3,
      'bye' : 5,
      'someone' : 1 }

the function will return

    { 3: 'hello',
      5: 'bye',
      1: 'someone' }

The function does not have to deal with non-invertible dictionaries. The
received dictionary will always be invertible.

Observation

Only the function will be evaluated. If your submission includes a main
program (e.g. with testmod), it must be either commented out or inside a
condition if __name__ == ’__main__’

Problem information

Author: ProAl1

Generation: 2026-01-25T16:40:01.449Z

© Jutge.org, 2006–2026.
https://jutge.org
