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'}
Поиск
Категории
Больше
Desktop Publishing
Desktop Publishing
Desktop publishing system (NIS) is a set of equipment for preparing the original layout of the...
От FWhoop Xelqua 2023-03-04 17:57:41 0 22Кб
Business
What Is Business Development / What Does a Business Development Manager Do?
Business development (BD) is one of the most misunderstood functions in modern organizations....
От Dacey Rankins 2025-11-14 21:11:33 0 2Кб
Телевидение
Прямой эфир телеканала "Россия 24"
«Россия-24» — общероссийский федеральный государственный информационный...
От Nikolai Pokryshkin 2022-09-29 21:28:37 0 26Кб
Деньги
How to Make Money Online
How to Make Money Online In today’s digital age, making money online has become more...
От Leonard Pokrovski 2025-09-20 17:34:15 0 6Кб
Personal Finance
How do I switch to a higher-paying career?
How do I switch to a higher-paying career? Best-paying fields requiring minimal retraining...
От Leonard Pokrovski 2025-12-02 21:51:19 0 4Кб

BigMoney.VIP Powered by Hosting Pokrov