Choose Category
package main import ( "bufio" "fmt" "io" "log" "os" "strings" ) func main() { file, err := os.Open("cars.txt") if err != nil { log.Fatalln(err) } defer file.Close() counts := wordCount(file) fmt.Println("Number of count is", counts["audi"]) } func wordCount(rdr io.Reader) map[string]int { counts := map[string]int{} scanner := bufio.NewScanner(rdr) scanner.Split(bufio.ScanWords) for scanner.Scan() { word := scanner.Text() word = strings.ToLower(word) counts[word]++ } return counts }