Python Dictionary Key/Value Swap

0
5كيلو بايت

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'}
البحث
الأقسام
إقرأ المزيد
Television
Fiji One, Live TV.
Fiji One is based in Suva and is a publicly listed company on the South Pacific Stock Exchange....
بواسطة Nikolai Pokryshkin 2022-11-12 14:04:03 0 17كيلو بايت
Научная фантастика и фэнтези
Звёздные войны: Эпизод 4 — Новая надежда. Star Wars: Episode IV - A New Hope. (1977)
Татуин. Планета-пустыня. Уже постаревший рыцарь Джедай Оби Ван Кеноби спасает молодого Люка...
بواسطة Nikolai Pokryshkin 2022-11-21 21:46:44 0 22كيلو بايت
Mental Health
Autism Spectrum: Alternative medicine
A multitude of researched alternative therapies have also been implemented. Many have resulted in...
بواسطة Kelsey Rodriguez 2023-03-17 18:19:08 0 6كيلو بايت
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 16كيلو بايت
Business
Product placement: what is, types, goals
In this article, we will learn what product placement is, what it allows you to achieve, what...
بواسطة Dacey Rankins 2024-09-27 14:11:40 0 21كيلو بايت
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov