go-examples/example-wordcount/main.go

21 lines
348 B
Go
Raw Normal View History

2017-07-07 12:29:36 +00:00
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))
}