Skip to content

Instantly share code, notes, and snippets.

@nmpeterson
Last active December 18, 2015 18:09
Show Gist options
  • Save nmpeterson/5823269 to your computer and use it in GitHub Desktop.
Save nmpeterson/5823269 to your computer and use it in GitHub Desktop.
Convert a string to Title Case. (No cleverness: 'iPhone' will become 'Iphone'.)
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