Python Dictionary Key/Value Swap
نشر بتاريخ 2023-03-03 21:55:48
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'}
البحث
الأقسام
- Arts
- Business
- Computers
- الألعاب
- Health
- الرئيسية
- Kids and Teens
- مال
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
إقرأ المزيد
How Do I Use User Behavior Analysis in Marketing, Product Development, or UX Design?
User behavior analysis (UBA) is the practice of studying how people interact with a product,...
What Makes Your Company Better Than Competitors?
This question invites employers to highlight their unique strengths and competitive advantages....
Autism Spectrum: Other Features
Autistic individuals may have symptoms that do not contribute to the official diagnosis, but that...
How Do Platform Algorithms Influence Content Visibility and Reach?
In the digital age, content creators, marketers, and businesses all strive for greater visibility...
Gone with the Wind. (1939)
American motion picture classic in which a manipulative woman and a roguish man conduct a...