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))
import codewars_test as test from solution import capitalize_sentence @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(capitalize_sentence('i am a python programmer'), 'I Am A Python Programmer') test.assert_equals(capitalize_sentence('EAT, SLeeP, cODE, rePEAT!'), 'Eat, Sleep, Code, Repeat!') test.assert_equals(capitalize_sentence('I will EraDicate my EnemiEs and 3xtinguish the l1ght of their HOPE'), 'I Will Eradicate My Enemies And 3xtinguish The L1ght Of Their Hope')
- import codewars_test as test
- from solution import capitalize_sentence
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(capitalize_sentence('i am a python programmer'), 'I Am A Python Programmer')
test.assert_equals(capitalize_sentence('EAT, SLeeP, cODE, rePEAT!'), 'Eat, Sleep, Code, Repeat!')- test.assert_equals(capitalize_sentence('EAT, SLeeP, cODE, rePEAT!'), 'Eat, Sleep, Code, Repeat!')
- test.assert_equals(capitalize_sentence('I will EraDicate my EnemiEs and 3xtinguish the l1ght of their HOPE'), 'I Will Eradicate My Enemies And 3xtinguish The L1ght Of Their Hope')