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
إقرأ المزيد
Agriculture and Forestry: Pillars of Sustainability and Global Prosperity
Agriculture and forestry are two of the oldest and most essential human activities, serving as...
Understanding Business Associations: Strengthening Networks and Promoting Growth
Business associations play a crucial role in fostering collaboration, advocacy, and support among...
What Is the Difference Between Tax-Deductible, Tax-Deferred, and Tax-Free?
What Is the Difference Between Tax-Deductible, Tax-Deferred, and Tax-Free?
Taxes affect nearly...
Million Dollar Baby. (2004)
A determined woman works with a hardened boxing trainer to become a professional.
My Link
Judgment at Nuremberg. (1961)
In 1948, an American court in occupied Germany tries four Nazis judged for war crimes.
My Link