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
Models
Exploring the Art of Recreation on Models: A Fusion of Innovation and Nostalgia
Exploring the Art of Recreation on Models: A Fusion of Innovation and...
Por Leonard Pokrovski 2024-05-14 23:26:38 0 20KB
Television
WMAR 2 ABC Live TV Baltimore, Maryland, United States.
WMAR-TV, channel 2, is the ABC-affiliated television station in Baltimore, Maryland, United...
Por Nikolai Pokryshkin 2022-11-05 13:26:13 0 33KB
Programming
JavaScript Library
In the past, you would create a new file, paste your code and place this file in every project...
Por Jesse Thomas 2023-06-09 21:35:17 0 11KB
Business
What Is the Best Sales Management Software?
Sales management software sits at the center of modern sales organizations. It connects people,...
Por Dacey Rankins 2025-12-23 19:49:47 0 2KB
Personal Finance
How Can I Save Money Automatically?
How Can I Save Money Automatically? A Practical Guide to Automation Tools and Smart Bank...
Por Leonard Pokrovski 2025-12-08 19:38:05 0 4KB

BigMoney.VIP Powered by Hosting Pokrov