-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.py
More file actions
58 lines (43 loc) · 1.14 KB
/
lib.py
File metadata and controls
58 lines (43 loc) · 1.14 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from string import ascii_letters
def length_of_str(text: str) -> int:
counter = 0
for char in text:
counter += 1
return counter
def word_count(text: str) -> int:
if text == "":
return 0
counter = 0
is_letter = False
for char in text:
if char != " ":
is_letter = True
elif is_letter:
counter += 1
is_letter = False
if is_letter:
counter += 1
return counter
def sentences_count(text: str) -> int:
counter = 0
while text:
to_slice_count = 1
if text[:3] == '...':
counter += 1
to_slice_count = 3
elif text[:2] == '?!':
counter += 1
to_slice_count = 2
elif text[0] in '.!?':
counter += 1
text = text[to_slice_count:]
return counter
def filter_of_letter(char: str) -> bool:
return char in ascii_letters
def letter_count(text: str) -> int:
# counter = 0
# for char in text:
# if char.isalpha():
# counter += 1
# return counter
return len(list(filter(filter_of_letter, text)))