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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Business
What is Business Ethics?
Business ethics is a field of study that deals with the principles, standards, and moral...
από Dacey Rankins 2025-01-30 15:58:17 0 12χλμ.
Business
Infrastructure as a Service (IaaS): Virtual Infrastructure Delivery
Infrastructure as a Service (IaaS) is a cloud service model that allows you to rent virtual...
από Dacey Rankins 2024-09-25 17:33:58 0 24χλμ.
Science Fiction and Fantasy
Back to the Future. (1985)
Marty McFly, a 17-year-old high school student, is accidentally sent 30 years into the past in a...
από Leonard Pokrovski 2022-11-24 18:54:33 0 34χλμ.
Science Fiction and Fantasy
Aquaman. (2018)
Arthur Curry, the human-born heir to the underwater kingdom of Atlantis, goes on a quest to...
από Leonard Pokrovski 2023-05-01 20:24:58 0 30χλμ.
Business
What are marketing communications?
Marketing communications, like any other communications, consist of certain elements, these are:...
από Dacey Rankins 2024-09-03 19:04:06 0 14χλμ.

BigMoney.VIP Powered by Hosting Pokrov