Python Dictionary Key/Value Swap

0
13كيلو بايت

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'}
البحث
الأقسام
إقرأ المزيد
التعليم
How to study to become a doctor in different countries of the world
How to study to become a doctor in different countries of the world Australian National...
بواسطة Leonard Pokrovski 2024-04-15 21:48:43 0 23كيلو بايت
الادوات
Tools used to rennovate
If the Fixies really existed, they would be the most welcome guests in every home. However, they...
بواسطة FWhoop Xelqua 2023-05-14 21:08:16 0 23كيلو بايت
Television
Omega Gospel Live TV. South African Republic.
OMEGA Gospel TV Network is a Christian-based broadcast platform that continuously airs a unique...
بواسطة Nikolai Pokryshkin 2022-11-29 18:14:45 0 32كيلو بايت
Science Fiction and Fantasy
The Terminator. (1984)
A human soldier is sent from 2029 to 1984 to stop an almost indestructible cyborg killing...
بواسطة Leonard Pokrovski 2023-04-28 19:18:14 0 28كيلو بايت
Reproductive Health
What is reproductive health?
What is reproductive health? What is reproductive health? Reproductive...
بواسطة Leonard Pokrovski 2024-04-19 01:00:36 0 19كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov