Python Dictionary Key/Value Swap

0
13KB

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
Companies
Computer Companies: Key Players in a Digital World
The computer industry has evolved dramatically since its inception, driven by innovation and...
Por Dacey Rankins 2024-10-16 15:49:54 0 20KB
Business
What Is Influence?
A Complete Guide to Understanding Influence in Psychology, Leadership, Communication, and...
Por Dacey Rankins 2025-11-25 10:53:36 0 2KB
Business
How Do I Start Vlogging?
Introduction Vlogging — or video blogging — has evolved from a casual hobby into a...
Por Dacey Rankins 2025-11-11 18:14:39 0 6KB
Public Health and Safety
Public health management is the process of managing a complex system
Public health management is the process of managing a complex system Public health is the...
Por Leonard Pokrovski 2024-04-19 00:45:25 0 18KB
Социальные проблемы
Бен-Гур. Ben-Hur. (1959)
Действие фильма начинается в Палестине в 26 году от Рождества Христова. Два друга, иудей Бен Гур...
Por Nikolai Pokryshkin 2023-03-23 18:08:29 0 37KB

BigMoney.VIP Powered by Hosting Pokrov