Python Dictionary Key/Value Swap

0
13K

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'}
Zoeken
Categorieën
Read More
Телевидение
Общественное телевидение Приморья. Прямой эфир.
Общественное телевидение Приморья — главный региональный телеканал, вещающий круглосуточно...
By Nikolai Pokryshkin 2022-10-25 10:08:57 0 26K
Mental Health
Scizophrenia Positive Symptoms
signs and symptoms  Schizophrenia is a mental disorder characterized by significant...
By Kelsey Rodriguez 2023-01-25 17:03:18 0 13K
Marketing and Advertising
How Do I Optimize an AdWords Campaign?
Launching a Google AdWords (Google Ads) campaign is only the beginning. The real difference...
By Dacey Rankins 2026-01-13 13:57:21 0 2K
Personal Finance
What are the costs of K–12 schooling vs university? — a practical, illustrated guide
What are the costs of K–12 schooling vs university? — a practical, illustrated guide...
By Leonard Pokrovski 2025-10-31 20:36:06 0 7K
Central America
Why can't you travel from North America to South America by car
North and South America are connected by a narrow strip of land - the Isthmus of Panama, several...
By FWhoop Xelqua 2023-03-07 18:03:02 0 20K

BigMoney.VIP Powered by Hosting Pokrov