Skip to content

Instantly share code, notes, and snippets.

@devennorton
Created November 19, 2019 06:30
Show Gist options
  • Save devennorton/14acd42be61326d8d1c1a6698c73f64a to your computer and use it in GitHub Desktop.
Save devennorton/14acd42be61326d8d1c1a6698c73f64a to your computer and use it in GitHub Desktop.
def title_case(title, minor_words):
final = ""
minor_words = [word.lower() for word in minor_words ] # make sure the minor words are all lower case
title = title.lower().split() # make title all lowercase and split into a list of words
final = title[0].capitalize() # always capitalize the first word
for word in title[1:]: #capitalize words not in list
if word not in minor_words:
final += ' ' + word.capitalize()
return final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment