Python Dictionary Key/Value Swap

0
9KB

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'}
Pesquisar
Categorias
Leia mais
Телевидение
Первый Музыкальный канал, прямой эфир. Беларусь
«Первый музыкальный» — музыкальный телеканал из Беларуси. Телеканал транслирует...
Por Nikolai Pokryshkin 2022-11-20 22:18:19 0 30KB
Business
What is the Best Business Structure for a Startup?
Starting a business is an exciting and challenging endeavor. One of the most important decisions...
Por Dacey Rankins 2025-04-10 14:44:35 0 4KB
Природа и наука
Принцесса Мононоке. Princess Mononoke. (1997)
Убив вепря, юный принц Аситака навлек на себя смертельное проклятие. Старая знахарка предсказала,...
Por Nikolai Pokryshkin 2023-01-03 22:51:08 0 22KB
Business
What Strategies Do You Use to Prioritize Tasks Effectively?
In today’s fast-paced work environment, effective task prioritization is not just a...
Por Dacey Rankins 2025-05-14 14:08:18 0 3KB
Money
Money to Money: How to Learn to Save Correctly
A new smartphone, fashionable sneakers, studying at a prestigious university or traveling around...
Por Dacey Rankins 2024-10-22 16:11:07 0 11KB
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov