Python Dictionary Key/Value Swap

0
10K

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'}
Căutare
Categorii
Citeste mai mult
Gaelic
Gaelic: Unveiling the Rich Heritage and Enduring Legacy of Ireland's Indigenous Culture
  Gaelic: Unveiling the Rich Heritage and Enduring Legacy of...
By Leonard Pokrovski 2024-06-25 16:50:48 0 21K
Business
Automation of the company's business processes
Automation of the company's business processesAutomation of business processes helps to save...
By Dacey Rankins 2024-09-23 16:34:20 0 17K
Speech Technology
Computer Speech Technology
Computer speech technology, often referred to as speech recognition or speech synthesis,...
By Dacey Rankins 2024-11-01 13:59:54 0 12K
Mental Health
Psychosis: Culture
Cross-cultural studies into schizophrenia have found that individual experiences of psychosis and...
By Kelsey Rodriguez 2023-06-09 20:02:28 0 10K
E-Commerce
E-commerce
E-commerce is an area of the digital economy that includes all financial and trade transactions...
By FWhoop Xelqua 2023-07-27 18:12:03 0 31K

BigMoney.VIP Powered by Hosting Pokrov