Python Dictionary Key/Value Swap

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
Leia mais
Personal Finance
How to learn to spend money on yourself
Spending money on yourself without regrets, anxiety and guilt is an art that is not inherent in...
Por Dacey Rankins 2024-10-28 19:10:04 0 12KB
Business
Flower business at home
Flower business at home Opening a flower business at home can be a great idea...
Por Leonard Pokrovski 2024-07-22 21:02:09 0 22KB
Business
Common Etiquette Rules in the Business Environment
Business etiquette is more than a set of formalities — it is a framework for building...
Por Dacey Rankins 2025-11-25 10:52:04 0 4KB
Personal Finance
How Salary Ranges Work: Minimum, Midpoint, Maximum, and Pay Bands
How Salary Ranges Work: Minimum, Midpoint, Maximum, and Pay Bands Salary ranges are one of the...
Por Leonard Pokrovski 2025-11-28 20:56:15 0 4KB
Life Issues
Colombiana. (2011)
A young girl in Bogotá witnesses her parents' murder and grows up to be a stone-cold...
Por Leonard Pokrovski 2023-05-22 20:12:57 0 35KB

BigMoney.VIP Powered by Hosting Pokrov