Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Created June 14, 2020 08:04
Show Gist options
  • Save kurzweil777/98585181b3cd312f3f2ffb7e0f11b181 to your computer and use it in GitHub Desktop.
Save kurzweil777/98585181b3cd312f3f2ffb7e0f11b181 to your computer and use it in GitHub Desktop.
Exercise from code_wars
def title_case(title, minor_words=''):
"""Write a function that will convert a string into title case, given an optional list of exceptions (minor
words). The list of minor words will be given as a string with each word separated by a space. Your function
should ignore the case of the minor words string -- it should behave in the same way even if the case of the
minor word string is changed. """
words = []
minor_words = minor_words.lower().split()
for word in title.lower().split():
if word in minor_words:
words.append(minor_words[minor_words.index(word)])
words[0] = words[0].capitalize()
else:
words.append(word.capitalize())
return ' '.join(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment