// SortByValue returns the Keys in the sorted order of the Values (does not guarantee Stability)
SortByValue returns the Keys in the sorted order of the Values (does not guarantee Stability)
// SortByValue returns the Keys in the sorted order of the Values ( does not guarantee Stability )
func SortByValue(m map[string]string) (sortedKeys []string) {
	ValueToKey := make(map[string][]string)
	for k, v := range m {
		_, ok := ValueToKey[v]
		if !ok {
			ValueToKey[v] = []string{k}
		} else {
			temp := ValueToKey[v]
			ValueToKey[v] = append(temp, k)
		}
	}
	var uniqueValues []string
	for v := range ValueToKey {
		uniqueValues = append(uniqueValues, v)
	}
	sort.Strings(uniqueValues)
	for _, v := range uniqueValues {
		keys := ValueToKey[v]
		sortedKeys = append(sortedKeys, keys...)
	}
	return
}
func SortByValue ( m map [ string ] string ) ( sortedKeys [ ] string ) { ValueToKey := make ( map [ string ] [ ] string ) for k , v := range m { _ , ok := ValueToKey [ v ] if ! ok { ValueToKey [ v ] = [ ] string { k } } else { temp := ValueToKey [ v ] ValueToKey [ v ] = append ( temp , k ) } } var uniqueValues [ ] string for v := range ValueToKey { uniqueValues = append ( uniqueValues , v ) } sort . Strings ( uniqueValues ) for _ , v := range uniqueValues { keys := ValueToKey [ v ] sortedKeys = append ( sortedKeys , keys ... ) } return }
SortByValue returns the Keys in the sorted order of the Values (does not guarantee Stability)
SortByValue returns the Keys in the sorted order of the Values ( does not guarantee Stability )
// create a reverse lookup mapping that can handle collisions // (duplicates) when the same value has multiple occurrences // sort the Values // get the corresponding Keys