Python Dictionary Key/Value Swap

0
12KB

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
Stories
Casablanca. (1942)
A cynical expatriate American cafe owner struggles to decide whether or not to help his former...
Por Leonard Pokrovski 2022-12-05 19:06:06 0 26KB
Социальные проблемы
Волк с Уолл-стрит. The Wolf of Wall Street. (2013)
1987 год. Джордан Белфорт становится брокером в успешном инвестиционном банке. Вскоре банк...
Por Nikolai Pokryshkin 2023-02-08 11:17:12 1 33KB
Finance
What Is Foreclosure?
What Is Foreclosure? Foreclosure is a legal process that occurs when a homeowner fails to make...
Por Leonard Pokrovski 2025-10-05 19:27:12 0 5KB
Business
How much money do I need to start a business?
Starting a business is an exciting journey, but one of the biggest questions aspiring...
Por Dacey Rankins 2025-03-12 15:47:16 0 12KB
Illustration
The Art of Illustration: A Journey Through Visual Storytelling
Illustration is one of the most powerful forms of visual communication, blending artistry with...
Por Dacey Rankins 2024-11-20 16:36:14 0 10KB

BigMoney.VIP Powered by Hosting Pokrov