Python Dictionary Key/Value Swap
Postado 2023-03-03 21:55:48
0
13KB
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
- Recreation
- Reference
- Regional
- Science
- Shopping
- Society
- Sports
- Бизнес
- Деньги
- Дом
- Досуг
- Здоровье
- Игры
- Искусство
- Источники информации
- Компьютеры
- Наука
- Новости и СМИ
- Общество
- Покупки
- Спорт
- Страны и регионы
- World
Leia mais
For a Few Dollars More. (1965)
Two bounty hunters with the same intentions team up to track down an escaped Mexican outlaw....
The Assistant. (2020)
A searing look at a day in the life of an assistant to a powerful executive. As Jane follows her...
What is B2C Marketing? Understanding Business-to-Consumer Strategies
Business-to-Consumer (B2C) marketing refers to the strategies and tactics that businesses use to...
Do I Need to Hire a PR Firm or Can I DIY? A Complete Guide for Modern Businesses
Introduction: The PR Dilemma for Businesses
Every business, whether a startup or a global...
The Sixth Sense. (1999)
A frightened, withdrawn Philadelphia boy who communicates with spirits seeks the help of a...