Python Dictionary Key/Value Swap

0
9χλμ.

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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Television
Fox 4 Live TV. Dallas, Texas, United States.
Fox Dallas (KDFW), is a Fox-affiliated television station located in Dallas, Texas, United...
από Nikolai Pokryshkin 2022-10-19 09:54:56 0 28χλμ.
Programming
JavaScript Built-in Methods
What are built-in methods? A JavaScript method is a property containing...
από Jesse Thomas 2023-05-30 22:07:31 0 9χλμ.
Business
How Do I Scale My Startup?
Scaling a startup is a thrilling milestone, but it comes with its own unique set of challenges....
από Dacey Rankins 2025-04-10 14:56:20 0 4χλμ.
Научная фантастика и фэнтези
ВАЛЛ-И. WALL·E (2008)
Робот ВАЛЛ·И из года в год прилежно трудится на опустевшей Земле, очищая нашу планету от...
από Nikolai Pokryshkin 2022-12-14 10:18:15 0 29χλμ.
Weather
Weather
A weather forecast is a scientifically based assumption about the future state of the weather in...
από FWhoop Xelqua 2023-03-24 17:35:47 0 14χλμ.
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov