Python Dictionary Key/Value Swap
Δημοσιευμένα 2023-03-03 21:55:48
0
8χλμ.
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
- Money
- News
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Διαβάζω περισσότερα
Top 10 Magazines of the week
Frieze
Frieze Magazine Website
The respected British art magazine celebrated its 20th...
FOX 2, Live TV San Francisco USA
KTVU Fox 2 gives the power of two local newscasts at night. The Eleven O'Clock News updates the...
What ethical practices should I follow as a content creator?
As a content creator, you have a unique influence over your audience, and with that influence...
Autism Spectrum: Management
There is no treatment as such for autism, and many sources advise that this is not an appropriate...
Unlocking the Power of References in Bibliographies: A Comprehensive Guide
Unlocking the Power of References in Bibliographies: A Comprehensive Guide
Bibliographies are...