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 Комментарии 0 Поделились 12Кб Просмотры 0 предпросмотр
Спонсоры

Dating Gpykin

Find real love on Dating Gpykin - connect free through voice and video!


BigMoney.VIP Powered by Hosting Pokrov