I know there are many solutions (How do I sort a dictionary by value?) to sorting a dictionary by values. However, most of those predate python 3.7's changes to dictionary.
I am also aware of Fastest way to sort a python 3.7+ dictionary, which seems close to the answer I need.
I have a large dictionary of keys that are ints and values that are sets of strings.
I want to create a new dictionary that is sorted by the length of the set of each value.
Dictionary:
dict1={
'12':{'sym1', 'sym2'},
'13':{'sym1', 'sym4', 'sym5', 'sym6'},
'14':{'sym1', 'sym3'},
'15':{'sym2'},
'16':{'sym2'},
'17':{'sym2'},
'18':{'sym3', 'sym89', 'sym34', 'sym5', 'sym88'}
}
New sorted dictionary:
>>sorted_dict1
{
'18':{'sym3', 'sym89', 'sym34', 'sym5', 'sym88'},
'13':{'sym1', 'sym4', 'sym5', 'sym6'},
'12':{'sym1', 'sym2'},
'14':{'sym1', 'sym3'},
'15':{'sym2'},
'16':{'sym2'},
'17':{'sym2'}
}