1def beginning(word):
2 length = len(word)
3 if length % 3 == 0:
4 return word[: length // 3]
5 elif length % 3 == 1:
6 return word[: length // 3]
7 else:
8 return word[: length // 3 + 1]
9
10def middle(word):
11 length = len(word)
12 if length % 3 == 0:
13 return word[length // 3 : 2 * (length // 3)]
14 elif length % 3 == 1:
15 return word[length // 3 : 2 * (length // 3) + 1]
16 else:
17 return word[length // 3 + 1 : 2 * (length // 3) + 1]
18
19def end(word):
20 length = len(word)
21 if length % 3 == 0 :
22 return word[length - length//3:]
23 elif length % 3 == 1 :
24 return word[length - length // 3:]
25 else:
26 return word[length - (length // 3 + 1):]
27
28def split_sentence(sentence):
29 words = sentence.split()
30 split_words = []
31
32 for w in words:
33 split_words.append((beginning(w), middle(w), end(w)))
34
35 return split_words
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
n | 3 | if(length % 3 == 0): | n | 3 | if length % 3 == 0: |
4 | return word[0 : length // 3] | 4 | return word[: length // 3] | ||
5 | elif(length % 3 == 1): | 5 | elif length % 3 == 1: | ||
6 | return word[0 : length // 3] | 6 | return word[: length // 3] | ||
7 | else: | 7 | else: | ||
n | 8 | return word[0 : length // 3 + 1] | n | 8 | return word[: length // 3 + 1] |
9 | 9 | ||||
10 | def middle(word): | 10 | def middle(word): | ||
11 | length = len(word) | 11 | length = len(word) | ||
n | 12 | if(length % 3 == 0): | n | 12 | if length % 3 == 0: |
13 | return word[length // 3 : 2 * (length // 3)] | 13 | return word[length // 3 : 2 * (length // 3)] | ||
n | 14 | elif(length % 3 == 1): | n | 14 | elif length % 3 == 1: |
15 | return word[length // 3 : 2 * (length // 3) + 1] | 15 | return word[length // 3 : 2 * (length // 3) + 1] | ||
16 | else: | 16 | else: | ||
17 | return word[length // 3 + 1 : 2 * (length // 3) + 1] | 17 | return word[length // 3 + 1 : 2 * (length // 3) + 1] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
n | 21 | if(length % 3 == 0): | n | 21 | if length % 3 == 0 : |
22 | return word[length - length//3:] | 22 | return word[length - length//3:] | ||
n | 23 | elif(length % 3 == 1): | n | 23 | elif length % 3 == 1 : |
24 | return word[length - length // 3:] | 24 | return word[length - length // 3:] | ||
25 | else: | 25 | else: | ||
26 | return word[length - (length // 3 + 1):] | 26 | return word[length - (length // 3 + 1):] | ||
27 | 27 | ||||
28 | def split_sentence(sentence): | 28 | def split_sentence(sentence): | ||
t | 29 | sentence += ' ' | t | 29 | words = sentence.split() |
30 | wordBeg = 0 | ||||
31 | i = 0 | ||||
32 | words = [] | 30 | split_words = [] | ||
33 | length = len(sentence) | 31 | |||
34 | while(i < length): | 32 | for w in words: | ||
35 | if(sentence[i] == ' '): | ||||
36 | word = sentence[wordBeg : i] | ||||
37 | words.append((beginning(word), middle(word), end(word))) | 33 | split_words.append((beginning(w), middle(w), end(w))) | ||
38 | wordBeg = i + 1 | 34 | |||
39 | i+=1 | ||||
40 | return words | 35 | return split_words |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|