Capitalize Every Word (Title Case)

Easy ⏱ 8 min 87% acceptance ★★★★★ 4.7
Write capitalize_words(s) that returns s with the first letter of every word capitalized and the rest of each word lowercased, where words are separated by single spaces. Do not use str.title(), since it mishandles words containing apostrophes.

Examples

Example 1
Input
s = 'the quick brown fox'
Output
'The Quick Brown Fox'
Explanation

Each word gets its first letter capitalized.

Example 2
Input
s = 'HELLO there WORLD'
Output
'Hello There World'
Explanation

Rest of each word is forced to lowercase, regardless of input casing.

Constraints

  • Words are separated by single spaces, no leading/trailing spaces.
  • 1 <= len(s) <= 500

Topics

StringsCase Conversion

Companies

FlipkartZomatoHCLTech

Hints

Hint 1

Split on spaces, then use `word.capitalize()` on each piece.

Hint 2

Rejoin with `" ".join(...)`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.