-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamelcase.py
29 lines (24 loc) · 961 Bytes
/
camelcase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Sentence(object):
def __init__(self, sentence):
if isinstance(sentence, str):
self.sentence = sentence
else:
raise TypeError("Sentence must be a String object")
def list_distinct_upper_lower_cases(self):
"""
Transform the sentence (String object) in a list of 0 and 1.
Represent Lowercase by 0.
Represent Uppercase by 1.
"""
return [1 if e.isupper() else 0 for e in self.sentence ]
def count_words(self):
"""
Number of words equal to:
- Count of ones in list_distinct_upper_lower_cases(self)
- (+1) for the first word of the sentence
"""
return 1 + sum(self.list_distinct_upper_lower_cases())
if __name__ == '__main__':
sentence_string = "thisIsATestToCountNumberOfWordsInASentenceWithUpperAndLowerCase"
sentence_object = Sentence(sentence_string)
print(sentence_object.count_words())