Python Dictionary Key/Value Swap
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'}
0 Comments 0 Shares 4K Views 0 Reviews
Sponsored

Smart Base for TV

A rotating TV base that suits your TV watching needs! This TV base can rotate and adjust to the amount of people watching it, to make it the best watching experience for everyone. It comes with a...

image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov