Python Dictionary Key/Value Swap
نشر بتاريخ 2023-03-03 21:55:48
0
8كيلو بايت
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
إقرأ المزيد
ADHD: Possible Positive Traits
Possible positive traits of ADHD are a new avenue of research, and therefore limited.
A 2020...
Токийская повесть. Tokyo Story. (1953)
Пожилая супружеская пара едет из провинции в Токио навестить детей: сына, ставшего доктором, и...
How Do Startup CEOs Manage Work-Life Balance?
In the high-octane world of startups, where agility and rapid decision-making are often the keys...
Большой Лебовски. The Big Lebowski. (1998)
Лос-Анджелес, 1991 год, война в Персидском заливе. Главный герой по прозвищу Чувак считает себя...
Best VPNs
The essence is simple: you install a program that establishes a connection to a remote server...