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
- Binary to Decimal — Medium
- RGB to Hex Color — Easy
- Valid Palindrome — Medium
- Count the Vowels — Easy
- DNA Mutations — Easy
- GC Content — Easy