Practice: Word Frequency
Count words with a HashMap.
Example
fn main() {
use std::collections::BTreeMap;
let mut m = BTreeMap::new();
for w in "the cat and the hat".split_whitespace() { *m.entry(w).or_insert(0) += 1; }
println!("{:?}", m);
}Result
{"and": 1, "cat": 1, "hat": 1, "the": 2}Exercise
Split on spaces.
s.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.