go-examples/example-wordcount/main.go
2017-07-07 14:29:36 +02:00

21 lines
348 B
Go

package main
import "fmt"
import "os"
import "strings"
func wc(text string) map[string]uint {
words := make(map[string]uint)
for _, word := range strings.Fields(text) {
words[word]++
}
return words
}
func main() {
input := strings.Join(os.Args[1:], " ")
fmt.Println(input)
fmt.Println(strings.Repeat("-", 80))
fmt.Println(wc(input))
}