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'}
Pesquisar
Categorias
Leia Mais
Телевидение
Христианский телеканал GNC
GNC — Первый Христианский спутниковый телеканал на русском и украинском языках,...
Por Nikolai Pokryshkin 2022-08-30 10:47:57 0 29K
Financial Services
How to make big amounts of money
How to Make Big MoneyThe desire to earn big money should have a practical implementation in the...
Por FWhoop Xelqua 2023-06-13 19:49:49 0 23K
Телевидение
Телеканал «Губерния». Прямой эфир.
Телеканал Губерния ТВ - это национальный канал Хабаровского края. В эфире телеканала новостные...
Por Nikolai Pokryshkin 2022-11-17 20:18:32 0 30K
Business
What Is Prospecting in Sales?
In sales, nothing meaningful happens until you find the right people to sell to. That first step...
Por Dacey Rankins 2025-12-08 18:28:12 0 2K
Internet
How to make Money Online Fast
How to make money quickly on the InternetContentAdvantages and disadvantages of making money on...
Por FWhoop Xelqua 2023-05-27 18:59:51 0 26K

BigMoney.VIP Powered by Hosting Pokrov