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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Спорт
Семь самураев. Seven Samurai. (1954)
Япония, XVI век. В стране полыхает гражданская война, повсюду орудуют банды разбойников и...
από Nikolai Pokryshkin 2022-11-15 17:46:10 0 33χλμ.
Television
RTД Documentary Channel. Live TV. Russia.
Documentary channel RT Doc joined the RT news family in 2011. Since then, RT Doc has produced and...
από Nikolai Pokryshkin 2022-11-15 18:42:42 0 35χλμ.
Support Groups
The Importance of Health Support Groups: Empowering Individuals on Their Wellness Journey
Health support groups play a vital role in helping individuals navigate physical and emotional...
από Dacey Rankins 2024-12-09 13:37:46 0 11χλμ.
Спорт
Морской заговор: Тайна устойчивого рыболовства. Seaspiracy. (2021)
Все документальные события данного кинофильма от Netflix, который имеет название "Морской...
από Nikolai Pokryshkin 2022-09-11 23:33:17 0 36χλμ.
Business
What Role Does Company Culture Play in Team Motivation?
Company culture is more than just a buzzword—it’s the foundation that shapes how...
από Dacey Rankins 2025-05-20 14:47:29 0 8χλμ.

BigMoney.VIP Powered by Hosting Pokrov