forked from course-work/week1
Done
This commit is contained in:
parent
4d75bca7c1
commit
4f7408d40d
@ -1,7 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
def titlecase( string, exceptions ):
|
def titlecase( sentence, exceptions ):
|
||||||
pass
|
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 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' )
|
assert( titlecase( 'THE vitamins ARE IN my fresh CALIFORNIA raisins', ['are', 'is', 'in', 'your', 'my'] ) == 'The Vitamins are in my Fresh California Raisins' )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user