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'}
البحث
الأقسام
إقرأ المزيد
Social Issues
L.A. Confidential. (1997)
As corruption grows in 1950s Los Angeles, three policemen - one strait-laced, one brutal, and one...
بواسطة Leonard Pokrovski 2023-01-30 14:31:19 0 24كيلو بايت
Track and Field
Track and Field: Embracing the Essence of Athleticism
Track and field, the epitome of athletic prowess and human achievement, encompasses a diverse...
بواسطة Dacey Rankins 2024-07-12 17:24:30 0 23كيلو بايت
Animation
The Art of Animation: A Journey Through Motion and Imagination
Animation has evolved from simple sketches to complex digital masterpieces, captivating audiences...
بواسطة Dacey Rankins 2024-10-17 17:39:28 0 23كيلو بايت
Социальные проблемы
Барри Линдон. Barry Lyndon. (1975)
История жизни простого ирландского парня Редмонда Барри. Будучи еще совсем молодым, он убил на...
بواسطة Nikolai Pokryshkin 2023-03-28 18:37:15 0 38كيلو بايت
Internet
Google Ads Guide (2022). Part 4: All about the CMC
Part 3: Ad guides, how to properly set up google ads part 3 (bigmoney.vip) Here's how it works:...
بواسطة FWhoop Xelqua 2023-02-05 20:22:07 0 21كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov