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'}
Поиск
Категории
Больше
Office Products
An Overview of Essential Office Products: Tools for Efficiency and Productivity
Office products are the unsung heroes that keep workplaces running smoothly, whether in a...
От Dacey Rankins 2024-12-03 15:31:48 0 15Кб
Personal Finance
Who Needs to File a Tax Return?
  Who Needs to File a Tax Return? Do I Have to File Even If I Didn’t Make Much...
От Leonard Pokrovski 2025-11-19 21:57:04 0 5Кб
Business
Aristotle is the most influential person in philosophy.
Aristotle is the most influential person in philosophy. Aristotle is the most influential...
От Leonard Pokrovski 2024-07-24 12:42:33 0 16Кб
Human Resources
How Do Personnel Managers Evaluate Performance?
Performance evaluation is a critical function of personnel management that ensures employees are...
От Dacey Rankins 2026-04-10 20:07:16 0 892
Mental Health
Dyslexia: Screening
Screening procedures seek to identify children who show signs of possible dyslexia. In the...
От Kelsey Rodriguez 2023-07-03 18:20:15 0 11Кб

BigMoney.VIP Powered by Hosting Pokrov