Python Dictionary Key/Value Swap

0
11KB

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
Aging
The secret of eternal youth. What are the causes of human aging and death?
We age for a reason, but as a result of a special biological program. But there is an African...
Por Dacey Rankins 2024-04-15 19:50:05 0 15KB
СМИ
Талант шмеля. The Talent of the Hornet (2020)
Стэф – популярный диджей Радио 105, его изображение висит на одном из небоскрёбов в самом...
Por Nikolai Pokryshkin 2022-09-10 16:29:05 0 28KB
Телевидение
Прямой эфир телеканала ЛенТВ24
"ЛенТВ24" – региональный телеканал, вещающий на Санкт-Петербург и Ленинградскую область....
Por Nikolai Pokryshkin 2022-10-21 13:56:05 0 23KB
Programming
Send Emails With Python
Python comes with the built-in smtplib module for sending emails using the Simple...
Por Jesse Thomas 2023-05-08 21:34:55 0 10KB
Business
Frequently Asked Questions on Conflict Resolution and Mediation
Conflict is a natural part of human interaction, whether in the workplace, community, or personal...
Por Dacey Rankins 2025-06-10 15:21:17 0 5KB

BigMoney.VIP Powered by Hosting Pokrov