Python Dictionary Key/Value Swap

0
8Кб

You can change the keys and values in a dictionary using a loop and items(). This can be helpful if the key doesn't exist in the dictionary, but the value exist. Here's an example:

d = {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}

d_swap = {v: k for k, v in d.items()}
print(d_swap)
# {'val1': 'key1', 'val2': 'key2', 'val3': 'key3'}
Поиск
Категории
Больше
Business
Why does a start-up business need marketing?
Why does a start-up business need marketing? It seems that the English-language term...
От Leonard Pokrovski 2024-08-30 00:02:17 0 12Кб
Жизненные вопросы
Форрест Гамп. Forrest Gump. (1994)
Сидя на автобусной остановке, Форрест Гамп — не очень умный, но добрый и открытый парень...
От Nikolai Pokryshkin 2022-11-05 21:02:16 0 24Кб
Desktop Publishing
The Concept of Desktop Publishing
The concept of computer publishing systems appeared in connection with the development of...
От FWhoop Xelqua 2023-03-29 17:55:11 0 15Кб
Airsoft
Airsoft; is it dangerous?
Airsoft originated in Japan after World War II. Weapons were banned in the country, and the...
От FWhoop Xelqua 2023-03-05 18:15:43 0 18Кб
Business
When Should a Startup Founder Hire Employees?
One of the most critical decisions a startup founder faces is knowing when to hire employees....
От Dacey Rankins 2025-04-11 16:59:51 0 2Кб
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov