Python Dictionary Key/Value Swap

0
14K

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'}
Search
Categories
Read More
Business
How to Implement Automation in a Company?
Implementing automation in a company is not just about installing software—it’s about...
By Dacey Rankins 2026-04-27 21:11:59 0 2K
Business
What Is SaaS (Software as a Service)?
Most people use SaaS every day without realizing they are participating in one of the most...
By Dacey Rankins 2026-05-13 12:17:02 0 4K
People
50 artists that left a mark in history
50 artists and their works that have left a mark on history and people's hearts...
By FWhoop Xelqua 2023-07-09 18:10:51 0 33K
Business
How Do I Tailor Feedback for Bosses, Peers, and Reports?
Giving feedback isn’t one-size-fits-all. How you deliver feedback should vary depending on...
By Dacey Rankins 2025-07-29 17:38:25 0 5K
Human Resources
What Is Outsourcing?
In today’s global and highly competitive business environment, companies are constantly...
By Dacey Rankins 2026-04-02 18:48:14 0 2K

BigMoney.VIP Powered by Hosting Pokrov