Python Dictionary Key/Value Swap

0
12K

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'}
Buscar
Categorías
Read More
Internet
Windows OS will be transferred to the "cloud"
Microsoft has planned to completely transfer the Windows operating system (OS) to the "cloud"...
By FWhoop Xelqua 2023-06-28 18:03:35 0 24K
Жизненные вопросы
Три билборда на границе Эббинга, Миссури. Three Billboards Outside Ebbing, Missouri. (2017)
Спустя несколько месяцев после убийства дочери Милдред Хейс преступники так и не найдены....
By Nikolai Pokryshkin 2023-03-07 23:38:28 0 26K
Business
How to Write a Business Plan for a Small Business: A Step-by-Step Guide
Writing a business plan is an essential step for any small business owner looking to formalize...
By Dacey Rankins 2024-12-23 15:59:47 0 12K
Transportation and Logistics
Understanding Transportation and Logistics: The Backbone of Global Trade
Transportation and logistics are two closely intertwined sectors that are essential for the...
By Dacey Rankins 2024-11-25 14:21:22 0 12K
Телевидение
Вести Хакасия. ТВ прямой эфир.
В настоящее время филиал ВГТРК ГТРК «Хакасия» является структурным подразделением...
By Nikolai Pokryshkin 2022-10-24 10:03:37 0 28K

BigMoney.VIP Powered by Hosting Pokrov