Python Dictionary Key/Value Swap

0
12χλμ.

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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Социальные проблемы
Довод. Tenet. (2020)
После теракта в киевском оперном театре агент ЦРУ объединяется с британской разведкой, чтобы...
από Nikolai Pokryshkin 2022-10-15 22:43:39 0 34χλμ.
Lacrosse
Lacrosse | What is Lacrosse?
Lacrosse (French pronunciation: [lacrosse]; la crosse ("stick") is a team game in which two teams...
από FWhoop Xelqua 2023-01-05 17:11:57 0 18χλμ.
Business
What Is Product Planning?
Product planning is one of the most essential activities in business strategy and product...
από Dacey Rankins 2025-08-20 15:37:11 0 4χλμ.
Regional
Art of Western Europe in the 1800's
The eighteenth century in Western Europe is the last stage of the long transition from feudalism...
από FWhoop Xelqua 2023-07-12 18:20:50 0 30χλμ.
Moving and Relocating
The Ultimate Guide to Relocating: Tips for a Smooth Move
Relocating can be both an exciting and daunting experience. Whether you’re moving to a new...
από Dacey Rankins 2024-10-29 15:28:31 0 13χλμ.

BigMoney.VIP Powered by Hosting Pokrov