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'}
البحث
الأقسام
إقرأ المزيد
Mental Health
Autism Spectrum: Neuropathology
Listed below are some characteristic findings in ASD brains on molecular and cellular levels...
بواسطة Kelsey Rodriguez 2023-02-28 19:53:50 0 11كيلو بايت
Moving and Relocating
Countries That Pay to Relocate in 2024
Countries That Pay to Relocate in 2024 Which countries pay money for moving? For a long time, I...
بواسطة Leonard Pokrovski 2024-04-26 19:42:34 0 16كيلو بايت
Software
The Evolution of Software: Transforming Our World
Software is an essential component of modern technology, acting as the invisible backbone that...
بواسطة Dacey Rankins 2024-10-14 18:35:16 0 18كيلو بايت
Социальные проблемы
К северу через северо-запад. North by Northwest. (1959)
Однажды успешного рекламного агента Роджера Торнхилла ошибочно принимают за агента разведки...
بواسطة Nikolai Pokryshkin 2023-01-16 18:44:14 0 23كيلو بايت
Искусство, культура и развлечения
Друзья на свою голову. A Friendly Tale... (2020)
Леа и Марк, Карин и Франсис – две пары закадычных друзей. Но когда скромная тихоня Леа...
بواسطة Nikolai Pokryshkin 2022-09-30 20:35:52 0 25كيلو بايت

BigMoney.VIP Powered by Hosting Pokrov