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'}
البحث
الأقسام
إقرأ المزيد
Life Issues
The Truman Show. (1998)
An insurance salesman discovers his whole life is actually a reality TV show. My Link
بواسطة Leonard Pokrovski 2023-02-12 17:03:11 0 21كيلو بايت
Marketing and Advertising
How Do I Target the Right Audience on Facebook?
Audience targeting is one of the most powerful—and most misunderstood—parts of...
بواسطة Dacey Rankins 2026-01-21 19:01:31 0 998
Business
10 Examples of Gamification in Building Customer Relationships
What is relationship selling?The term "relationship sales" describes an approach that is the...
بواسطة Dacey Rankins 2024-09-09 19:37:26 0 14كيلو بايت
Internet
History of the Internet
History of the Internet The Internet is a worldwide computer network, the many nodes of...
بواسطة Leonard Pokrovski 2024-03-25 22:10:13 0 26كيلو بايت
Wholesale Trade
Myths about wholesale sales
Many people are afraid to sell goods in bulk, as they believe that this requires large material...
بواسطة Dacey Rankins 2024-03-19 16:06:35 0 37كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov