Python Dictionary Key/Value Swap
Postado 2023-03-03 21:55:48
0
13K
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'}
Pesquisar
Categorias
- Arts
- Business
- Computers
- Jogos
- Health
- Início
- Kids and Teens
- Money
- News
- Personal Development
- Recreation
- Regional
- Reference
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Личное развитие
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Leia Mais
What Regulations Apply to Outdoor Advertising?
Outdoor advertising is one of the most visible forms of marketing, which is why it is also one of...
What Advertising Biographies Are Used in Business Schools?
Business schools do not teach advertising solely through frameworks, metrics, and case studies....
The Automotive Business: Driving Innovation and Global Economy
The automotive business is one of the largest and most influential industries in the world. From...
How Are Companies Adjusting Remote Work Policies Post-Pandemic?
The COVID-19 pandemic revolutionized the way people work, with millions of employees...
What are the cards by purpose. Meaning and classification of geographical maps
What are the cards by purpose. Meaning and classification of geographical mapsFor the first time,...