Ctrl K

Headline Casing

Easy
An editorial team wants every article headline in one consistent style. The headline headline is made of Latin-letter words separated by exactly one space, and the letter case is all over the place. The rule is: - a word of one or two letters is written entirely in lowercase; - a word of three or more letters gets an uppercase first letter and lowercase for the rest. Return the headline restyled by this rule.
Example 1
headline="NEW cafe IN the OLD town" → 'New Cafe in The Old Town'

Words of three or more letters get a capital first letter; "IN" is shorter, so it goes all lowercase.

Example 2
headline="a dOg TO walk" → 'a Dog to Walk'

"a" and "TO" are short and become lowercase; "dOg" and "walk" become "Dog" and "Walk".

Constraints
  • 1 ≤ len(headline) ≤ 100
  • Words are non-empty and consist of uppercase and lowercase Latin letters
  • Words are separated by exactly one space, with no leading or trailing spaces
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
headline="NEW cafe IN the OLD town"
Expected
'New Cafe in The Old Town'

Run checks the first 3 tests in your browser. Submit checks all 137 tests on the server, hidden ones included.