Files
curriculum/1.solar-system/3.strings/06.the-counter/index.md

839 B

type, title, xp, duration, difficulty
type title xp duration difficulty
challenge The Counter 75 30 3

The Counter

[INCOMING — Mission Control, Earth]

Cadet, time to count things in text. Three counts:

  • Total lengthlen(s)
  • Word countlen(s.split()) (split breaks on whitespace)
  • a counts.lower().count("a") returns how many as

Implement count(s) that returns a dict with three keys:

  • length — total chars including spaces
  • words — word count
  • a_count — number of lowercase as after lowercasing

[END TRANSMISSION]

Your Task

In starter/starter.py, build the dict using len(), .split(), .lower(), .count().

Objectives

  • count("Hello andromeda"){"length": 15, "words": 2, "a_count": 2}
  • All three keys present and correct for any sentence