Python Dictionary Key/Value Swap

0
12KB

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'}
Rechercher
Catégories
Lire la suite
Социальные проблемы
Как быть хорошей женой. How to Be a Good Wife. (2020)
Хранить очаг и не мешкая исполнять супружеский долг: так учит Полетт Ван дер Бек в своей домашней...
Par Nikolai Pokryshkin 2022-10-23 16:26:44 0 29KB
Financial Services
Shifts in aggregate demand
Key points The aggregate demand/aggregate supply model is a model that...
Par Mark Lorenzo 2023-03-29 20:02:04 0 12KB
Personal Finance
Should I Pay Off Debt First, or Save and Invest First?
Should I Pay Off Debt First, or Save and Invest First? Balancing today’s burdens with...
Par Leonard Pokrovski 2025-11-10 18:34:18 0 2KB
Business
What Problem Does Your Product Solve?
Every successful product starts with a problem. In fact, most innovations are not born from a...
Par Dacey Rankins 2025-08-18 13:29:51 0 4KB
Научная фантастика и фэнтези
Интерстеллар. Interstellar. (2014)
Когда засуха, пыльные бури и вымирание растений приводят человечество к продовольственному...
Par Nikolai Pokryshkin 2022-11-19 17:29:10 0 35KB

BigMoney.VIP Powered by Hosting Pokrov