Among U.S. book publishers (but not newspaper publishers), it is a common typographic practice to capitalize "important" words in titles and headings. This is an old form of emphasis, similar to the more modern practice of using a larger font or a boldface font for titles. This family of typographic conventions is usually called title case.

title case

The rules for which words to capitalize are not based on any grammatically inherent correct/incorrect distinction and are not universally standardized. They are arbitrary and differ between style guides, although most styles they tend to follow a few strong conventions. In general, most styles capitalize all words except for closed-class words: certain parts of speech such as articles (a, an, the), prepositions (in, to, at, …) and conjunctions (and, but, yet, …). The first word of a sentence is always capped, regardless of part of speech.

Assignment

Write a function titleCase that transforms a given sentence into title case. The function should capitalize the first letter of each word, whereas all other letters retain their original spelling. The words of a sentence are defined as the longest possible sequence of letters, quotes (') and hyphens (-). The given sentence must be passed as an argument to the function. The function also has a second optional parameter, that takes a list of words. Words from this list should never be capitalized, unless they appear as the first word of a sentence. Determining if a word belongs to the given list of words should happen case insensitive. The title cased sentence must be returned by the function.

Example

>>> words = ['above', 'about', 'across', 'against', 'along', 'among', 'around', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'between', 'beyond', 'by', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'since', 'to', 'toward', 'through', 'under', 'until', 'up', 'upon', 'with', 'within', 'a', 'the', 'an', 'and', 'but', 'or', 'nor', 'yet', 'so', 'to']

>>> titleCase('Great minds think of great things.')
'Great Minds Think Of Great Things.'

>>> titleCase('Great minds think of great things.', words)
'Great Minds Think of Great Things.'

>>> titleCase("You and I share the same DNA.", words)
'You and I Share the Same DNA.'