1def beginning(word):
2 LENGTH = len(word)
3 numOfCharsToPrint = LENGTH // 3
4
5 if LENGTH % 3 == 2:
6 numOfCharsToPrint += 1
7
8 return word[:numOfCharsToPrint]
9
10
11def middle(word):
12 LENGTH = len(word)
13 numOfCharsToPrint = LENGTH // 3
14 BEGIN_INDEX = numOfCharsToPrint if LENGTH % 3 != 2 else numOfCharsToPrint+1
15
16 if LENGTH % 3 == 1:
17 numOfCharsToPrint += 1
18
19 return word[BEGIN_INDEX:BEGIN_INDEX+numOfCharsToPrint]
20
21
22def end(word):
23 LENGTH = len(word)
24 numOfCharsToPrint = LENGTH // 3
25
26 if LENGTH % 3 == 2:
27 numOfCharsToPrint += 1
28
29 if not numOfCharsToPrint:
30 return ''
31
32 return word[-numOfCharsToPrint:]
33
34
35def split_sentence(sentence):
36 WORDS = sentence.split(' ')
37
38 return [(beginning(word), middle(word), end(word)) for word in WORDS]
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Георги Кунчев
17.10.2023 18:15Махаме една точка, заради неспазения `snake_case`.
|
16.10.2023 18:36
16.10.2023 18:36
16.10.2023 18:37
16.10.2023 18:37