shad-go/lectures/00-intro/uniq/uniq.go

21 lines
303 B
Go
Raw Permalink Normal View History

2020-02-13 11:45:11 +00:00
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
counts := make(map[string]int)
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
counts[input.Text()]++
}
// NOTE: ignoring potential errors from input.Err()
for line, n := range counts {
2020-02-13 12:47:08 +00:00
fmt.Printf("%d\t%s\n", n, line)
2020-02-13 11:45:11 +00:00
}
}