Python Dictionary Key/Value Swap

0
13K

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'}
Site içinde arama yapın
Kategoriler
Read More
Социальные проблемы
Наш отец. Our Father. (2020)
Рим, 1976 год. Семья Ле Розе ведет зажиточный образ жизни. У них дом в элитном районе Рима,...
By Nikolai Pokryshkin 2022-10-10 17:03:37 0 33K
Television
TMJ4 Live TV in Milwaukee, Wisconsin, USA
TMJ4 was the first commercial TV station in Wisconsin, hitting the airwaves on December 3, 1947....
By Nikolai Pokryshkin 2022-10-27 14:39:48 0 32K
Economics
What Is Economic Growth?
What Is Economic Growth?GDP Growth, Development, and Productivity Economic growth is one of the...
By Leonard Pokrovski 2026-01-28 19:46:30 0 671
Business
What Should Be in a Product Plan?
A product plan is one of the most important tools in product management. It provides clarity,...
By Dacey Rankins 2025-08-20 15:38:33 0 3K
Social Issues
Fargo. (1996)
Minnesota car salesman Jerry Lundegaard's inept crime falls apart due to his and his henchmen's...
By Leonard Pokrovski 2023-03-13 20:28:59 0 26K

BigMoney.VIP Powered by Hosting Pokrov