Python Dictionary Key/Value Swap

0
5KB

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'}
Search
Nach Verein filtern
Read More
Veranstaltungen
Understanding the Significance of Events: Exploring Moments that Shape Our Lives
Understanding the Significance of Events: Exploring Moments that Shape Our Lives Events are the...
Von Leonard Pokrovski 2024-05-25 11:14:06 0 18KB
История
Монти Пайтон и священный Грааль. Monty Python and the Holy Grail. (1975)
Король Артур и рыцари Круглого стола отправляются в невероятное путешествие на поиски Святого...
Von Nikolai Pokryshkin 2023-02-20 12:30:09 0 15KB
Социальные проблемы
Мисс Плохое поведение. Misbehaviour. (2020)
Англия, 1970-е, эпоха сексуальной революции и поисков новой свободы. Миллионы восторженных...
Von Nikolai Pokryshkin 2022-10-21 17:16:50 0 18KB
Television
FOX SOUL Live TV USA
Celebrate Black Culture. FOX SOUL is a streaming platform for The Culture! We amplify Black...
Von Nikolai Pokryshkin 2022-09-04 08:47:33 0 24KB
Mental Health
ADHD: IQ test performance
Certain studies have found that people with ADHD tend to have lower scores on intelligence...
Von Kelsey Rodriguez 2023-03-31 16:32:40 0 4KB
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov