Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created June 10, 2015 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanmhlv/d164b9e492453dbfb115 to your computer and use it in GitHub Desktop.
Save yanmhlv/d164b9e492453dbfb115 to your computer and use it in GitHub Desktop.
simple groupby
package main
import "log"
func groupBy(vars []int) map[int][]int {
result := make(map[int][]int)
for _, value := range vars {
result[value] = append(result[value], value)
}
return result
}
func main() {
log.Print(groupBy([]int{1,2,3,4,1,2,3,4}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment