blob: fc5c8eabcd84b0b9c1a8226ee17b8b0e454f661b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
use std::collections::HashMap;
fn main() {
let text = "once upon a time ...";
let mut word_counts = HashMap::new();
let pairs = text.split(" ")
.map(|x| { (x, 1) });
for (word, count) in pairs {
let tmp = word_counts.entry(word)
.or_insert(0);
*tmp += count;
}
println!("{:?}", word_counts);
}
|