Python Dictionary Key/Value Swap

0
12كيلو بايت

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'}
البحث
الأقسام
إقرأ المزيد
Business
How Do I Attract and Retain Donors?
Attracting and retaining donors is one of the most important aspects of running a successful...
بواسطة Dacey Rankins 2025-03-26 16:34:08 0 9كيلو بايت
Жизненные вопросы
Три билборда на границе Эббинга, Миссури. Three Billboards Outside Ebbing, Missouri. (2017)
Спустя несколько месяцев после убийства дочери Милдред Хейс преступники так и не найдены....
بواسطة Nikolai Pokryshkin 2023-03-07 23:38:28 0 25كيلو بايت
Business
LG launches Native Screensaver Ads. What is it?
The American company LG Ad Solutions, a division of the South Korean giant - the manufacturer of...
بواسطة Dacey Rankins 2024-09-18 17:35:52 0 17كيلو بايت
Business
Viral marketing: who is it suitable for and how to launch it
Viral marketing: who is it suitable for and how to launch it  What are we...
بواسطة Leonard Pokrovski 2024-08-29 23:55:03 0 20كيلو بايت
Социальные проблемы
Антебеллум. Antebellum. (2020)
Известная писательница, активистка и борец за права чёрных женщин Вероника Хенли оказывается в...
بواسطة Nikolai Pokryshkin 2022-10-14 21:00:31 0 39كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov