Reverse the Lookup

Sometimes you need to search by value instead of by key, like turning a code dictionary into a reverse reference. The function invert_dict receives a dictionary d and returns a new dictionary where keys and values have swapped places. All input values are distinct, so there will be no conflicts during the swap.

Примеры

Ввод
{"a": "x", "b": "y"}
Вывод
{"x": "a", "y": "b"}
Ввод
{}
Вывод
{}
Ввод
{"x": "y"}
Вывод
{"y": "x"}

Нужно реализовать

def invert_dict(d: dict) -> dict:

Теги

dicthashmap
PostgreSQLv16
Entre para enviar

O resultado da execução do código aparecerá aqui

Visible tests
1
Input
{"a":"x","b":"y"}
Expected{"x":"a","y":"b"}
2
Input
{}
Expected{}
3
Input
{"x":"y"}
Expected{"y":"x"}
4
Input
{"one":"1"}
Expected{"1":"one"}
5
Input
{"a":"p","b":"q"}
Expected{"p":"a","q":"b"}
6
Input
{"b":"y"}
Expected{"y":"b"}
Focus radio
Paused · SomaFM · Fluid