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
- Money
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Διαβάζω περισσότερα
What Are the Top Priorities or Expectations for This Role in the First 6 Months?
Understanding the top priorities for a role early on can help you decide whether it’s the...
В поисках Немо. Finding Nemo. (2003)
Рыба-клоун Марлин после трагической гибели жены в одиночку растит своего единственного сына Немо....
What Are the Main Responsibilities of a CEO?
The Chief Executive Officer (CEO) is the highest-ranking executive in a company, responsible for...
What Were the Major Challenges They Faced, and How Did They Overcome Them?
Every successful leader has a story shaped not just by victories, but by the challenges they...
The Power of Gameplay Groups: Building Community and Enhancing the Gaming Experience
Gaming has evolved far beyond being a solitary activity; it’s now a social, interactive...