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'}
البحث
الأقسام
إقرأ المزيد
القصص
For a Few Dollars More. (1965)
Two bounty hunters with the same intentions team up to track down an escaped Mexican outlaw....
بواسطة Leonard Pokrovski 2023-02-02 14:34:20 0 26كيلو بايت
Life Issues
Inside Out. (2016)
After young Riley is uprooted from her Midwest life and moved to San Francisco, her emotions -...
بواسطة Leonard Pokrovski 2023-03-06 18:28:32 0 20كيلو بايت
Future
Future
A future is a hypothetical segment of a timeline, a set of events that have not yet occurred, but...
بواسطة FWhoop Xelqua 2023-03-02 16:16:45 0 19كيلو بايت
Shopping
The Rise of Online Shopping: A Comprehensive Overview
In recent years, online shopping has transformed the way consumers purchase goods and services....
بواسطة Dacey Rankins 2024-10-10 17:10:13 0 24كيلو بايت
Mental Health
Psychosis: Neuroimaging
The first brain image of an individual with psychosis was completed as far back as 1935 using a...
بواسطة Kelsey Rodriguez 2023-06-05 19:02:07 0 11كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov