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'}
Rechercher
Catégories
Lire la suite
История
Телохранитель. Yojimbo. (1961)
В некий японский городок приходит самурай. Самурай выглядит совершенно не по-самурайски: плохо...
Par Nikolai Pokryshkin 2023-02-19 14:43:31 0 24KB
Argent
How to Get Student Loans Forgiven
How to Get Student Loans Forgiven Student loan forgiveness can provide financial relief for...
Par Leonard Pokrovski 2025-09-23 19:07:56 0 7KB
Life Issues
Before Sunset. (2004)
Nine years after Jesse and Celine first met, they encounter each other again on the French leg of...
Par Leonard Pokrovski 2023-06-16 20:35:25 0 40KB
Marketing and Advertising
How to Find Clients as a Copywriter
Introduction: Why Finding Clients Is the Real Challenge Many copywriters discover quickly that...
Par Dacey Rankins 2025-10-01 14:42:35 0 4KB
Business
What Universal Concerns Exist Around Growth?
Growth is a concept that stretches across every level of existence—from the individual to...
Par Dacey Rankins 2025-09-09 14:27:01 0 4KB

BigMoney.VIP Powered by Hosting Pokrov