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'}
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Financial Services
Aggregate demand in Keynesian analysis
Key points Aggregate demand is the sum of four components: consumption,...
από Mark Lorenzo 2023-03-15 17:18:10 0 20χλμ.
Office Products
Office Tools
Choosing office suppliesIs it time to stock up on office stationery? Not sure where to start?...
από FWhoop Xelqua 2023-03-25 16:24:05 0 25χλμ.
Ιστορίες
Unforgiven. (1992)
Retired Old West gunslinger William Munny reluctantly takes on one last job, with the help of his...
από Leonard Pokrovski 2023-02-14 14:32:39 0 20χλμ.
Business
How Often Should I Update My Business Biography?
A business biography serves as a personal and professional narrative that highlights the key...
από Dacey Rankins 2025-01-06 15:55:28 0 13χλμ.
Business
Top Questions to Ask Your Mentor
Entering a mentoring relationship is an exciting opportunity for growth, learning, and...
από Dacey Rankins 2025-05-26 14:06:14 0 6χλμ.

BigMoney.VIP Powered by Hosting Pokrov