Python Dictionary Key/Value Swap

0
7KB

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'}
Rechercher
Catégories
Lire la suite
Ужасы
Дальний космос. Stowaway (2021)
Экипаж космического корабля, направляющегося на Марс, обнаруживает на борту случайного пассажира...
Par Nikolai Pokryshkin 2022-09-18 22:13:39 0 55KB
Телевидение
Телеканал Доктор Градус. Прямая трансляция.
Телеканал «Доктор Градус» целиком посвящен нетрадиционной медицине. При просмотре...
Par Nikolai Pokryshkin 2022-11-18 12:54:04 0 16KB
Opportunities
Top 20 Most Important Questions for Business
Top 20 Most Important Questions for Business   An entrepreneur should answer...
Par Leonard Pokrovski 2024-03-15 19:28:54 0 25KB
Costumes
Easy Halloween Costumes: Quick and Creative Ideas
Halloween is just around the corner, and while some enjoy elaborate costumes, others prefer...
Par Dacey Rankins 2024-10-08 17:58:44 0 10KB
Writers Resources
Top 9 Useful Writing sites
Your creative process as a science fiction writer may be different from that of your peers, but...
Par FWhoop Xelqua 2023-07-14 18:00:30 0 17KB
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov