Python Dictionary Key/Value Swap

0
14Кб

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'}
Поиск
Категории
Больше
Marketing and Advertising
How Do I Avoid Annoying Customers with Remarketing Ads? A Complete Guide to Respectful and Effective Retargeting
  How Do I Avoid Annoying Customers with Remarketing Ads? A Complete Guide to Respectful...
От Dacey Rankins 2026-02-12 20:37:04 0 9Кб
Home Improvement
7 Tips to Improve Home Comfort
According to the principles of feng shui, an ancient Eastern practice, it takes very little to...
От FWhoop Xelqua 2022-09-18 12:26:47 0 43Кб
Productivity
How to be more productive during the day?
How to Be More Productive During the Day Productivity is often misunderstood as simply...
От Michael Pokrovski 2026-04-27 20:48:41 0 1Кб
Economics
What is a floating exchange rate?
What Is a Floating Exchange Rate? A floating exchange rate is a system in which the value of a...
От Leonard Pokrovski 2026-08-13 20:27:42 0 250
Business
How Do I Write a Professional Business Biography?
A professional business biography is a powerful tool that provides insight into your career...
От Dacey Rankins 2024-12-27 15:57:28 0 39Кб

BigMoney.VIP Powered by Hosting Pokrov