Title Case

Easy · rating 1050 · Strings

Read a single line of words separated by single spaces. Print it in title case: the first letter of each word uppercased and the rest of each word lowercased.

For example, the LAZY dog becomes The Lazy Dog.

Editorial

Approach

Split the line on spaces, and for each word uppercase its first character and lowercase the remainder, then rejoin with single spaces. Lowercasing the tail is what turns LAZY into Lazy.

words = input().split(' ')
print(' '.join(w[:1].upper() + w[1:].lower() for w in words))

Complexity

Time: O(n). Space: O(n).

Related problems

Open Title Case in Code Arena →