title_case('a clash of KINGS', 'a an the of') # should return: 'A Clash of Kings'
title_case('THE WIND IN THE WILLOWS', 'The In') # should return: 'The Wind in the Willows'
title_case('the quick brown fox') # should return: 'The Quick Brown Fox'
解决方案可以是:
def title_case(title, minor_words=''):
title = title.capitalize().split()
minor_words = minor_words.lower().split()
return ' '.join([word if word in minor_words else word.capitalize() for word in title])
如果'word'在'minor_words'中,请加入'minor_words'==>这不是我们想要的。我们想加入“头衔”
我试着用这个和不用这个写“小词”,结果是一样的。