Now I Am doing very small question at HackRank about string manipulations it is very easy one just like homework dump . The question is turn a given string to capitalize they mentioned their question just like below
You are given a string . Your task is to capitalize each word of S.
A single line of input containing the string, S.
0< len(s) <1000
If you don't specifiy the separator to
str.split(), "any whitespace string is a separator and empty strings are removed from the result." Note that here "whitespace" includes tabs, newlines etc.
The problem is not clearly specified (there's no definition of what "word" means) and we don't know what they use for test cases, but I assume they have a couple string with newlines or such. Anyway: explicitely specifying
" " as the separator makes the tests pass:
# Python 2 s = raw_input() print " ".join(x.capitalize() for x in s.strip().split(" ")) # Python 3 s = input() print(" ".join(x.capitalize() for x in s.strip().split(" ")))