Python Dictionary Key/Value Swap

0
12KB

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'}
Suche
Kategorien
Mehr lesen
Ужасы
Дьявол в деталях. The Little Things. (2021)
Октябрь 1990 года. Уже немолодого заместителя окружного шерифа Джо Дикона по прозвищу Дики...
Von Nikolai Pokryshkin 2022-09-21 17:31:15 0 38KB
Play-By-Mail
Play by mail
Play by mail games (also known asPBM games,PBEM games or turn-based games) is a gameplayed via...
Von FWhoop Xelqua 2022-11-30 16:44:37 0 22KB
Business
How Do I Find the Right Mentor?
Finding the right mentor can be one of the most rewarding steps in your personal and professional...
Von Dacey Rankins 2025-07-18 17:42:34 0 7KB
Chemistry
TOP 10 discoveries and events in the chemical industry in 2021
Another difficult year is behind us. Political, socio-economic and climatic changes every day...
Von FWhoop Xelqua 2023-01-25 16:19:56 0 23KB
Spiele
New Year's games
A home New Year's holiday is a long-standing good tradition. Older family members want to give...
Von FWhoop Xelqua 2022-12-06 16:18:49 0 40KB

BigMoney.VIP Powered by Hosting Pokrov