Python Dictionary Key/Value Swap
نشر بتاريخ 2023-03-03 21:55:48
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'}
البحث
الأقسام
- Arts
- Business
- Computers
- الألعاب
- Health
- الرئيسية
- Kids and Teens
- مال
- News
- Personal Development
- Recreation
- Regional
- Reference
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Личное развитие
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
إقرأ المزيد
What are newbies afraid of in tabletop RPGs?
Let's start breaking down the fun
I'm willing to bet you've definitely heard of tabletop...
What Is Conflict Resolution and Why Is It Important?
Conflict resolution refers to the methods and processes involved in facilitating the peaceful...
Exploring Health Professions: A Vital Sector of Healthcare
Health professions play a crucial role in ensuring the well-being of individuals and communities...
How Do I Pitch to Clients?
1. What Does It Mean to Pitch to Clients?
A client pitch is a conversation or presentation...
Top Conflict Management Interview Questions With Answers in 2025
Conflict is inevitable in any workplace, but how it’s managed can determine team success,...