问题:
I often have to sort a dictionary, consisting of keys & values, by value. 我经常需要按值排序字典,包括键和值。 For example, I have a hash of words and respective frequencies, that I want to order by frequency. 例如,我有一个单词和各自频率的哈希,我想按频率排序。
There is a SortedList which is good for a single value (say frequency), that I want to map it back to the word. 有一个SortedList适用于单个值(比如频率),我想将它映射回单词。
SortedDictionary orders by key, not value. SortedDictionary按键排序 ,而不是值。 Some resort to a custom class , but is there a cleaner way? 有些人诉诸于自定义课程 ,但是有更清洁的方法吗?
解决方案:
参考一: https://stackoom.com/question/4f/你如何按价值排序字典参考二: https://oldbug.net/q/4f/How-do-you-sort-a-dictionary-by-value
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4330664