Python Dictionary Key/Value Swap

0
5Кб

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'}
Поиск
Категории
Больше
СМИ
В случае убийства набирайте «М». Dial M for Murder. (1954)
Тони Вендис, бывший плейбой и звезда большого тенниса, прожигающий деньги своей красавицы-жены...
От Nikolai Pokryshkin 2023-03-06 15:23:34 0 14Кб
Mental Health
Autism Spectrum: Screening
About half of parents of children with ASD notice their child's atypical behaviors by age 18...
От Kelsey Rodriguez 2023-03-08 15:02:27 0 4Кб
Financial Services
How to reduce taxes
It is said that only two things are inevitable in the world - death and taxes. The first really...
От FWhoop Xelqua 2023-05-30 18:55:27 0 18Кб
Senior Health
Health Features of an Elderly Person
Health Features of an Elderly Person   The health of mature and elderly people is...
От Leonard Pokrovski 2024-04-22 21:41:55 0 8Кб
Television
SMNI News (English) Live TV Philippines
Sonshine Media Network International (SMNI), is the official broadcasting arm of the Kingdom of...
От Nikolai Pokryshkin 2022-08-30 21:56:36 0 21Кб
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov