Title Case with Small Words

easy
Unit 3 · Strings III0/3 to milestone

Implement title_case(text) following a common style guide:

  • capitalise the first letter of each word and lower-case the rest
  • keep these small words lower case: a, an, and, as, at, but, by, for, in, of, on, or, the, to unless they are the first or last word
  • words separated by hyphens are capitalised on each part (state-of-the-art → State-of-the-Art, with the small-word rule applying to inner parts)
  • collapse runs of whitespace into single spaces
#strings2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Title Case with Small Words · TechGradify