From 4f7408d40de3a653227b90c12647552c6eaef8d4 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Sat, 23 Sep 2023 21:49:09 -0400 Subject: [PATCH] Done --- 01-title_case/title.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/01-title_case/title.py b/01-title_case/title.py index 6884dc8..daf72a6 100755 --- a/01-title_case/title.py +++ b/01-title_case/title.py @@ -1,7 +1,16 @@ #!/usr/bin/env python3 -def titlecase( string, exceptions ): - pass +def titlecase( sentence, exceptions ): + sentence = sentence.lower().split(' ') + out = [sentence[0].title()] + + for word in sentence[1:]: + if word in exceptions: + out.append(word) + else: + out.append(word.title()) + + return ' '.join(out) assert( titlecase( 'the quick brown fox jumps over the lazy dog', ['jumps', 'the', 'over'] ) == 'The Quick Brown Fox jumps over the Lazy Dog' ) assert( titlecase( 'THE vitamins ARE IN my fresh CALIFORNIA raisins', ['are', 'is', 'in', 'your', 'my'] ) == 'The Vitamins are in my Fresh California Raisins' )