Invert a Country-Code Dict

Medium ⏱ 12 min 54% acceptance ★★★★★ 4.7
Write invert(codes) that flips a dict like {'IN': 'India'} into {'India': 'IN'} with a dict comprehension. Assume values are unique — but uppercase the new values (the codes) in the same pass.

Examples

Example 1
Input
invert({'in': 'India', 'us': 'USA'})
Output
{'India': 'IN', 'USA': 'US'}
Explanation

Keys and values swap; codes get uppercased.

Constraints

  • Values in the input are unique.
  • One dict comprehension.

Topics

List Comprehensionsdict comprehension

Companies

GoogleOracle

Hints

Hint 1

Iterate .items() and swap positions.

Hint 2

Apply .upper() to the code as it becomes the value.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.