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
Больше
How Can the Product Be More Environmentally Friendly or Accessible?
In today’s marketplace, environmental sustainability and accessibility are no longer...
How Do I Find Common Ground or Shared Interests in a Negotiation?
Introduction: Why Common Ground Is the Heart of Every Successful Negotiation
Negotiation often...
How Do I Use Visuals or Slides Effectively During a Speech?
Slides can make your speech stronger — or weaker. When used well, they help your audience...
What is the Difference Between a Business Plan and a Business Model?
This question often comes up as people try to clarify the distinction between two critical...
What Are Media Relations? Building Strong Connections That Shape Public Perception
Introduction: Why Media Relations Matter More Than Ever
In a world overflowing with content and...