26 lines
509 B
Go
26 lines
509 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
fruits := "ananas orange apfel apfel\n aprikose kirche"
|
|
|
|
words := strings.Split(fruits, " ")
|
|
|
|
wordCount := make(map[string]int)
|
|
|
|
for _, word := range words {
|
|
word = strings.ReplaceAll(word, "\n", ""); // Wenn man newlines entfernen will
|
|
if strings.HasPrefix(word, "a") {
|
|
wordCount[word]++
|
|
}
|
|
}
|
|
|
|
for word, count := range wordCount {
|
|
fmt.Printf("%T: %v \n", word, count);
|
|
}
|
|
}
|