Python Dictionary Key/Value Swap

0
13KB

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'}
Pesquisar
Categorias
Leia mais
Science Fiction and Fantasy
2001: A Space Odyssey. (1968)
After uncovering a mysterious artifact buried beneath the Lunar surface, a spacecraft is sent to...
Por Leonard Pokrovski 2023-01-12 20:47:51 0 29KB
Business
What Is Sales Operations (SalesOps)?
Sales operations, often called SalesOps, is one of the most misunderstood — and most...
Por Dacey Rankins 2025-12-23 20:02:19 0 2KB
Социальные проблемы
Элегия Хиллбилли. Hillbilly Elegy. (2020)
Исследование темы американской мечты на примере трёх поколений одной семьи, живущих в горах...
Por Nikolai Pokryshkin 2022-10-06 22:16:57 0 28KB
Спорт
Дангал. Dangal. (2016)
История спортсмена Махавира Сингха Пхогата, который по причине бедности был вынужден бросить...
Por Nikolai Pokryshkin 2023-02-01 23:47:22 0 34KB
Business and Corporate Finance
What Is Business Finance? How Companies Manage Money
What Is Business Finance? How Companies Manage Money Introduction Every business, whether it is...
Por Leonard Pokrovski 2025-12-27 22:39:19 0 5KB

BigMoney.VIP Powered by Hosting Pokrov