Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Word Frequency Counter

Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.

Count how many times each whitespace-separated word appears. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement word_frequency(text: str) -> dict counting whitespace-separated words.

Requirements

  • Preserve first-seen insertion order.

Constraints

  • Words are separated by spaces.

Examples

Input: word_frequency('a b a') Output: {'a': 2, 'b': 1} Second 'a' increments the count.

Topics: lakebench, python, counting, strings.

More Python interview questions · All interview problems · Learn data engineering

beginner

Word Frequency Counter

Interview-style drill: Count how many times each whitespace-separated word appears.

Implement `word_frequency(text: str) -> dict` counting whitespace-separated words. Example: `"a b a"` → `{'a': 2, 'b': 1}`. Keep the harness.