There are a few problems with this. If you use split and join, some white space characters will be ignored. The built-in capitalize and title methods do not ignore white space.
>>> 'There is a way'.title()
'There Is A Way'
If a sentence starts with an article, you do not want the first word of a title in lowercase.
Keeping these in mind:
import re
def title_except(s, exceptions):
word_list = re.split(' ', s) # re.split behaves as expected
final = [word_list[0].capitalize()]
for word in word_list[1:]:
final.append(word if word in exceptions else word.capitalize())
return " ".join(final)
articles = ['a', 'an', 'of', 'the', 'is']
print title_except('there is a way', articles)
# There is a Way
print title_except('a whim of an elephant', articles)
# A Whim of an Elephant
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…