← Back to challenges

Game of Thrones: Character Titles

PythonHardstringsformattinglanguage_fundamentals

Instructions

Write a function that takes a string and returns a string with the correct case for character titles in the Game of Thrones series.

  • The words and, the, of and in should be lowercase.
  • All other words should have the first character as uppercase and the rest lowercase.

Examples

correct_title("jOn SnoW, kINg IN thE noRth.")
➞ "Jon Snow, King in the North."

correct_title("sansa stark, lady of winterfell.")
➞ "Sansa Stark, Lady of Winterfell."

correct_title("TYRION LANNISTER, HAND OF THE QUEEN.")
➞ "Tyrion Lannister, Hand of the Queen."

Notes

  • Punctuation and spaces must remain in their original positions.
  • Hyphenated words are considered separate words.
  • Be careful with words that contain and, the, of or in.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.