Pybites Logo Rust Platform

Word Count

Easy +2 pts

🎯 In Python, counting words is a one-liner with collections.Counter:

from collections import Counter
# simplified — doesn't strip punctuation
counts = Counter(s.lower().split())

In Rust, there's no Counter, but there's HashMap — and learning how to build one up is a fundamental Rust skill.

HashMap — Rust's dict

HashMap<K, V> is Rust's equivalent of Python's dict. Unlike Python where dict is a builtin, you need to import it:

use std::collections::HashMap;

let mut scores = HashMap::new();
scores.insert("Alice", 10);
scores.insert("Bob", 20);

Notice the mut — in Rust, variable bindings are immutable by default, so you need mut on scores

Login to see the full exercise.