Examples · learn/08-collections · 145 of 339
task-2.solution
tin run examples/learn/08-collections/task-2.solution.tinfn main() {
let text = "the cat saw the dog and the cat ran"
var counts: Map<string, int> = newMap()
for word in text.split(" ") {
counts.set(word, counts.get(word).or(0) + 1)
}
for word, n in counts {
print("{word}: {n}")
}
}