Python Dictionary Key/Value Swap

0
8كيلو بايت

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'}
البحث
الأقسام
إقرأ المزيد
Mental Health
ADHD: Possible Positive Traits
Possible positive traits of ADHD are a new avenue of research, and therefore limited. A 2020...
بواسطة Kelsey Rodriguez 2023-05-10 18:09:38 0 7كيلو بايت
Жизненные вопросы
Токийская повесть. Tokyo Story. (1953)
Пожилая супружеская пара едет из провинции в Токио навестить детей: сына, ставшего доктором, и...
بواسطة Nikolai Pokryshkin 2023-04-13 10:36:07 0 21كيلو بايت
Business
How Do Startup CEOs Manage Work-Life Balance?
In the high-octane world of startups, where agility and rapid decision-making are often the keys...
بواسطة Dacey Rankins 2025-05-05 14:45:01 0 1كيلو بايت
Спорт
Большой Лебовски. The Big Lebowski. (1998)
Лос-Анджелес, 1991 год, война в Персидском заливе. Главный герой по прозвищу Чувак считает себя...
بواسطة Nikolai Pokryshkin 2023-04-12 17:23:30 0 21كيلو بايت
الحماية
Best VPNs
The essence is simple: you install a program that establishes a connection to a remote server...
بواسطة FWhoop Xelqua 2023-05-02 20:06:53 0 12كيلو بايت
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov