Python Dictionary Key/Value Swap

0
13χλμ.

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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Systems
The most powerful computer in the world in 2022
Which computer is the most powerful in the world? Frontier HPE Cray EX235a is a new computer...
από FWhoop Xelqua 2023-04-14 16:35:38 0 21χλμ.
Informal Sports
Exploring the Charm and Benefits of Informal Sports
  Exploring the Charm and Benefits of Informal Sports...
από Leonard Pokrovski 2024-06-27 16:37:16 0 21χλμ.
Marketing and Advertising
What Are the Types of Outdoor Advertising?
Outdoor advertising, also known as out-of-home (OOH) advertising, includes a wide range of...
από Dacey Rankins 2026-01-30 19:36:04 0 1χλμ.
Business
How Long Should a Business Plan Be?
Searchers often want guidelines on the ideal length and depth of a business plan. Whether you're...
από Dacey Rankins 2024-12-18 16:48:08 0 16χλμ.
Internet
How to become popular on facebook
Popularity on Facebook depends on your ability to create engaging posts that will interest other...
από FWhoop Xelqua 2023-05-29 16:54:07 0 21χλμ.

BigMoney.VIP Powered by Hosting Pokrov