Ad
Code
Diff
  • from re import findall 
    
    def capitalize_sentence(sentence):
        return ''.join(f'{x[0].upper()}{x[1:].lower()}' for x in findall('[^ ]+|[ ]+', sentence))
    
    • from re import findall
    • def capitalize_sentence(sentence):
    • for i, word in enumerate(sentence.split(' ')):
    • cap_word = word[0].upper() + word[1:].lower()
    • sentence = sentence.replace(word, cap_word, 1)
    • return sentence
    • return ''.join(f'{x[0].upper()}{x[1:].lower()}' for x in findall('[^ ]+|[ ]+', sentence))