Word Lengths with a Dict Comprehension
Medium · Comprehensions
A dict comprehension builds a dictionary in one expression: {key: value for item in items if condition}. The if part is optional and filters items out.
Write word_lengths(text, min_length) that splits text on whitespace and returns a dict that maps each word (lowercased) to its length. Keep only words with at least min_length characters. A word that appears twice is still one key.
Next: Leaderboard Lines