Python Dictionary Key/Value Swap
Posted 2023-03-03 21:55:48
0
12K
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'}
Zoeken
Categorieën
- Arts
- Business
- Computers
- Spellen
- Health
- Home
- Kids and Teens
- Money
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Read More
What Are the Common Mistakes in Business Planning?
Many look for pitfalls to avoid while drafting their plans. Business planning is a critical part...
How Do I Stop Automatic Debit Payments from My Account?
How Do I Stop Automatic Debit Payments from My Account?
Automatic debit payments are a...
How to Promote Small Businesses: Strategies for Success
Promoting a small business can be a challenge, but with the right strategies, it is possible to...
What Industries Have the Highest Potential for Startups?
The startup ecosystem continues to thrive, with innovative entrepreneurs emerging from all...
Cornerstone Television Network. Live TV. Wall, Pennsylvania, USA.
Cornerstone Television began over 40 years ago – in a vision God gave Norma Bixler during a...