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'}
Search
Categories
- Arts
- Business
- Computers
- Games
- Health
- Home
- Kids and Teens
- Money
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Read More
Form of government
The form of state government is an element of the form of the state, which determines the system...
Can You Describe a Challenging Leadership Experience and How You Managed It?
In every leadership journey, challenges are not just inevitable—they are defining. One of...
Inside Job. (2010)
'Inside Job' provides a comprehensive analysis of the global financial crisis of 2008, which at a...
The most unusual newspapers and magazines in the world
1. Modern Drunkard Magazine - USAThe journal has been published every two months since 1996. Its...
How to Get a Credit Card
How to Get a Credit Card
Getting a credit card is an important financial step that can help you...