Problem 186309 · easy · Phase 01 Prerequisites & Setup

Character Census

strings · iteration · isalpha · isdigit · dictionaries

Given a string s, return a dictionary with four keys: "letters", "digits", "spaces" and "other", each mapped to how many characters of that kind appear in s. Every character belongs to exactly one category; "other" covers punctuation and symbols. All four keys must be present even when their count is 0.

Examples

Input:  s = "Hi 5!"
Output: {"letters": 2, "digits": 1, "spaces": 1, "other": 1}

Input:  s = ""
Output: {"letters": 0, "digits": 0, "spaces": 0, "other": 0}

Constraints

  • 0 <= len(s) <= 5000
  • s may contain letters, digits, spaces and printable punctuation

Goals

  • Classify each character with `isalpha`, `isdigit` and comparison
  • Count into a dictionary
Starting Python…