Python Dictionary Key/Value Swap

0
6KB

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'}
Search
Nach Verein filtern
Read More
Software
Software
Software (also known as software) is a program or set of programs used to control a computer...
Von FWhoop Xelqua 2023-04-04 16:47:07 0 20KB
Business
Tourists went into outer space for the first time in history. How this industry is developing
On September 12, the first ever tourist spacewalk took place. As part of the private mission...
Von Dacey Rankins 2024-09-24 14:47:56 0 15KB
Transgendered
Navigating the Complexities of Transgender Identity: Understanding, Acceptance, and Empowerment
Navigating the Complexities of Transgender Identity: Understanding, Acceptance, and Empowerment...
Von Leonard Pokrovski 2024-06-13 09:57:31 0 12KB
Искусство, культура и развлечения
Тайна Коко. Coco. (2017)
12-летний Мигель живёт в мексиканской деревушке в семье сапожников и тайно мечтает стать...
Von Nikolai Pokryshkin 2022-12-29 13:00:25 1 17KB
Science Fiction and Fantasy
Spider-Man: No Way Home. (2021)
With Spider-Man's identity now revealed, Peter asks Doctor Strange for help. When a spell goes...
Von Leonard Pokrovski 2023-02-26 16:46:05 0 13KB
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov