Python Dictionary Key/Value Swap

0
12χλμ.

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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Εργασία
Work From Home – Tips to Help You Stay Productive
Based on my experience, I've put together 15 tips for working from home to help you stay...
από FWhoop Xelqua 2022-09-10 17:01:30 0 35χλμ.
Business
What is a business accelerator?
What is a business accelerator?   A business...
από Leonard Pokrovski 2024-08-01 22:23:54 0 23χλμ.
Dentistry
How to take care of your teeth
How to take care of your teeth 1. Correct and regular brushing technique Simply...
από Leonard Pokrovski 2024-04-15 20:27:32 0 16χλμ.
Literature
The Power of Literature: Exploring the Depths of Human Experience
Literature is one of humanity's most cherished and enduring forms of expression. It encompasses...
από Dacey Rankins 2024-12-13 14:28:38 0 10χλμ.
Industrial Goods and Services
How are 3D printers used in industrial research and development? Industrial 3D Printer Buying Guide
How are 3D printers used in industrial research and development? Industrial 3D Printer...
από Leonard Pokrovski 2024-03-12 21:44:53 0 42χλμ.

BigMoney.VIP Powered by Hosting Pokrov