Python Dictionary Key/Value Swap
Veröffentlicht 2023-03-03 21:55:48
0
14KB
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'}
Suche
Kategorien
- Arts
- Business
- Computers
- Spiele
- Health
- Startseite
- Kids and Teens
- Geld
- News
- Personal Development
- Recreation
- Regional
- Reference
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Личное развитие
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Mehr lesen
Press Releases: Common Mistakes to Avoid and How to Measure Their Effectiveness
A press release remains one of the most powerful tools in public relations and marketing,...
What are the types of goals?
The blank page is a mirror. When we stare at it, we aren’t just looking for a place to...
Changes in equilibrium price and quantity: the four-step process
Key points
There is a four-step process that allows us to predict how an event...
How to finish assignments faster?
How to Finish Assignments Faster
Finishing assignments quickly is not about rushing or...
Jesus Live Network. Live TV. USA
Jesus Live Network was created to proclaim Jesus' Word, Purpose, and Power. It is an online...