This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
swb6-it-sec/Lab04/code/part01/main.go

27 lines
523 B
Go
Raw Normal View History

2022-05-30 09:36:08 +02:00
package main
import (
"fmt"
"strings"
)
func wordCount(str string) map[string]int {
wordList := strings.Fields(str)
counts := make(map[string]int)
for _, word := range wordList {
_, ok := counts[word]
if ok {
counts[word] += 1
} else {
counts[word] = 1
}
}
return counts
}
func main() {
strLine := "Australia Canada Germany Australia Japan Canada"
for index,element := range wordCount(strLine){
fmt.Println(index,"=>",element)
}
}