在Andrew Gerrand的Golang-nuts上找到了答案
您可以通过编写len / less / swap函数来实现sort接口
func rankByWordCount(wordFrequencies map[string]int) PairList{ pl := make(PairList, len(wordFrequencies)) i := 0 for k, v := range wordFrequencies { pl[i] = Pair{k, v} i++ } sort.Sort(sort.Reverse(pl)) return pl}type Pair struct { Key string Value int}type PairList []Pairfunc (p PairList) Len() int { return len(p) }func (p PairList) Less(i, j int) bool { return p[i].Value < p[j].Value }func (p PairList) Swap(i, j int){ p[i], p[j] = p[j], p[i] }对于原始帖子,请在这里https://groups.google.com/forum/#!topic/golang-
nuts/FT7cjmcL7gw找到


![如何通过Map [string] int的值对其排序? 如何通过Map [string] int的值对其排序?](http://www.mshxw.com/aiimages/31/409568.png)
