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
Shopping
The Evolution of Shopping: From Brick-and-Mortar to Click-and-Order
The Evolution of Shopping: From Brick-and-Mortar to Click-and-Order Shopping, once a simple...
Por Leonard Pokrovski 2024-05-27 22:19:40 0 17KB
Personal Finance
Why Do I Have Different Credit Scores?
Why Do I Have Different Credit Scores? If you’ve ever checked your credit score from more...
Por Leonard Pokrovski 2025-10-27 21:06:27 0 3KB
Personal Finance
How Often Should I Check My Credit Report?
How Often Should I Check My Credit Report? Your credit report is one of the most important...
Por Leonard Pokrovski 2025-10-27 21:08:13 0 4KB
Научная фантастика и фэнтези
Логан. Logan. (2017)
В недалеком будущем уставший от жизни Логан заботится о больном профессоре Икс, который прячется...
Por Nikolai Pokryshkin 2023-04-19 09:46:11 0 30KB
Crafts
The World of Art Crafts: Creativity, Culture, and Craftsmanship
Art crafts, often referred to as "handicrafts," represent a broad and diverse range of creative...
Por Dacey Rankins 2024-12-13 14:32:49 0 9KB

BigMoney.VIP Powered by Hosting Pokrov