Open this example in the interactive library
Source code
codes = {'red': 'R', 'blue': 'B'}
print({value: key for key, value in codes.items()})Sample output
{'R': 'red', 'B': 'blue'}
Invert unique values. A self-contained example using the Python standard library.
Open this example in the interactive library
codes = {'red': 'R', 'blue': 'B'}
print({value: key for key, value in codes.items()}){'R': 'red', 'B': 'blue'}