Python Dictionary Key/Value Swap
نشر بتاريخ 2023-03-03 21:55:48
0
9كيلو بايت
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'}
البحث
الأقسام
- Arts
- Business
- Computers
- الألعاب
- Health
- الرئيسية
- Kids and Teens
- مال
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
إقرأ المزيد
Аферистка. I Care a Lot. (2021)
Марла руководствуется принципом «побеждает сильнейший». Женщина организовала...
WTNH News 8 Newscasts Live TV. New Haven, Connecticut, USA.
WTNH, channel 8, is an ABC-affiliated television station located in New Haven, Connecticut, USA....
Parliament On Demand, Live TV, New Zealand.
Welcome to Parliament on Demand, the home of Parliament TV and all of New Zealand Parliament's...
The Role of Competition in Natural Selection and Evolution
Competition is a driving force in the natural world, shaping the survival and evolution of...
The Prom (2020)
In desperate need of a noble cause to revive their public images and bounce back, self-centred...