Last active
December 18, 2015 18:09
-
-
Save nmpeterson/5823269 to your computer and use it in GitHub Desktop.
Convert a string to Title Case. (No cleverness: 'iPhone' will become 'Iphone'.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def titlecase(in_str): | |
''' Convert a string to Title Case. Not very intelligent: | |
all words capitalized, and "iPhone" becomes "Iphone". ''' | |
words = in_str.split(' ') | |
for i in xrange(len(words)): | |
words[i] = words[i].capitalize() | |
title = ' '.join(words) | |
return title | |
# Example call: | |
titlecase('The wind in the willows') #=> 'The Wind In The Willows' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment