Python Dictionary Key/Value Swap

0
9Кб

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'}
Поиск
Категории
Больше
Business
How Do I Measure the Success of a Business Consulting Engagement?
When hiring a business consultant, companies invest not just in external expertise but in the...
От Dacey Rankins 2025-02-11 15:58:26 0 7Кб
Mental Health
How to make the brain work 100 percent at any age
For a long time, there was a hypothesis that, getting involved in any work, we use only 10% of...
От FWhoop Xelqua 2023-06-23 15:34:54 0 26Кб
Sport
Seaspiracy 2021
Passionate about ocean life, a filmmaker sets out to document the harm that humans do to marine...
От Leonard Pokrovski 2022-09-12 20:16:34 0 24Кб
Asia
17 places in Asia where it is worth visiting at least once in a lifetime
Natural phenomena of incredible beauty and structures erected by people with a century of history...
От FWhoop Xelqua 2022-09-19 16:55:01 0 59Кб
Orienteering
Discovering the Thrill of Sports Orienteering
Sports orienteering, a blend of physical prowess, strategic thinking, and navigating through...
От Dacey Rankins 2024-07-03 14:37:38 0 15Кб
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov