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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Социальные проблемы
Заводной апельсин. A Clockwork Orange. (1971)
Безжалостный лидер банды подростков, совершающей убийства и изнасилования, попадает в тюрьму и...
από Nikolai Pokryshkin 2023-01-19 18:54:12 0 30χλμ.
Ужасы
Молчание ягнят. The Silence of the Lambs. (1991)
Психопат похищает и убивает молодых женщин по всему Среднему Западу. ФБР, уверенное, что все...
από Nikolai Pokryshkin 2022-11-17 21:09:11 0 34χλμ.
Social Issues
Barry Lyndon. (1975)
An Irish rogue wins the heart of a rich widow and assumes her dead husband's aristocratic...
από Leonard Pokrovski 2023-03-29 19:57:20 0 27χλμ.
Business
How do I make an Instagram profile description for a business account?
On Instagram, the first impression of a profile affects whether a casual user stays with you...
από Dacey Rankins 2024-07-17 17:30:34 0 18χλμ.
Gay, Lesbian, and Bisexual
LGBTQIA+
LGBT is an acronym for lesbian, gay, bisexual, and transgender people. It appeared in English in...
από FWhoop Xelqua 2023-03-22 13:29:38 0 19χλμ.

BigMoney.VIP Powered by Hosting Pokrov