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'}
Pesquisar
Categorias
Leia mais
Board Games
Board games of the ancient world
When it comes to board games today, the average person first remembers dominoes and cards (less...
Por Michael Pokrovski 2024-04-02 19:06:35 0 21KB
Finance
What Is a Budget?
What Is a Budget? A budget is a financial plan that outlines how you will manage your income and...
Por Leonard Pokrovski 2025-10-05 19:25:20 0 3KB
Business
What is software licensing and how does it work?
Any software is a product of intellectual activity, so only the developer or copyright holder can...
Por Dacey Rankins 2024-09-25 17:52:31 0 25KB
Социальные проблемы
Мистер Смит едет в Вашингтон. Mr. Smith Goes to Washington. (1939)
Наивный идеалист Джефферсон Смит, лидер организации бойскаутов, назначен представителем в сенат....
Por Nikolai Pokryshkin 2023-04-03 12:48:59 0 43KB
Mental Health
Dyslexia
Dyslexia, previously known as word blindness, is a learning disability that affects reading....
Por Kelsey Rodriguez 2023-06-12 20:25:05 0 11KB

BigMoney.VIP Powered by Hosting Pokrov