blob: fc5c8eabcd84b0b9c1a8226ee17b8b0e454f661b (
plain) (
tree)
|
|
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);
}
|