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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Business
What Challenges Do Creators Face?
The Creator Economy has opened up countless opportunities for individuals to share their...
από Dacey Rankins 2025-02-24 16:02:51 0 12χλμ.
Mental Health
Psychosis: Medication
Administration, or sometimes withdrawal, of a large number of medications may provoke psychotic...
από Kelsey Rodriguez 2023-06-02 19:57:14 0 13χλμ.
Programming
JavaScript JSON.stringify()
A common use of JSON is to exchange data to/from a web server. When sending data to a web...
από Jesse Thomas 2023-05-10 22:18:01 0 12χλμ.
Adventure Racing
Unleashing the Thrill: Exploring the World of Sports Adventure Racing
In a world where athleticism meets adrenaline, sports adventure racing emerges as a vibrant...
από Dacey Rankins 2024-06-14 19:34:11 0 17χλμ.
Financial Services
effect of changes in policies and economic conditions on the foreign exchange market
Lesson summary Changes in the supply of or demand for a currency will cause that...
από Mark Lorenzo 2023-03-21 20:02:28 0 18χλμ.

BigMoney.VIP Powered by Hosting Pokrov