1def beginning(word):
2 if len(word) % 3 == 0 or len(word) % 3 == 1:
3 return word[:len(word) // 3]
4 elif len(word) % 3 == 2:
5 return word[:len(word) // 3 + 1]
6
7
8def middle(word):
9 if len(word) % 3 == 0:
10 return word[len(word) // 3:(len(word) // 3) * 2]
11 elif len(word) % 3 == 2:
12 return word[(len(word) // 3) + 1:(len(word) // 3) * 2 + 1]
13 elif len(word) % 3 == 1:
14 return word[len(word) // 3:((len(word) // 3) * 2) + 1]
15
16
17def end(word):
18 if len(word) % 3 == 0:
19 return word[(len(word) // 3) * 2:]
20 elif len(word) % 3 == 2 or len(word) % 3 == 1:
21 return word[((len(word) // 3) * 2) + 1:]
22
23
24def split_sentence(sentence):
25 output = []
26 for word in sentence.split():
27 output.append((beginning(word), middle(word), end(word)))
28 return output
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
f | 1 | f | 1 | ||
2 | 2 | ||||
n | 3 | def beginning(input): | n | 3 | def beginning(word): |
4 | if len(input) % 3 == 0 or len(input) % 3 == 1: | 4 | if len(word) % 3 == 0 or len(word) % 3 == 1: | ||
5 | return input[:len(input) // 3] | 5 | return word[:len(word) // 3] | ||
6 | elif len(input) % 3 == 2: | 6 | elif len(word) % 3 == 2: | ||
7 | return input[:len(input) // 3 + 1] | 7 | return word[:len(word) // 3 + 1] | ||
8 | 8 | ||||
9 | 9 | ||||
n | 10 | def middle(input): | n | 10 | def middle(word): |
11 | if len(input) % 3 == 0: | 11 | if len(word) % 3 == 0: | ||
12 | return input[len(input) // 3:(len(input) // 3) * 2] | 12 | return word[len(word) // 3:(len(word) // 3) * 2] | ||
13 | elif len(input) % 3 == 2: | 13 | elif len(word) % 3 == 2: | ||
14 | return input[(len(input) // 3) + 1:(len(input) // 3) * 2 + 1] | 14 | return word[(len(word) // 3) + 1:(len(word) // 3) * 2 + 1] | ||
15 | elif len(input) % 3 == 1: | 15 | elif len(word) % 3 == 1: | ||
16 | return input[len(input) // 3:((len(input) // 3) * 2) + 1] | 16 | return word[len(word) // 3:((len(word) // 3) * 2) + 1] | ||
17 | 17 | ||||
18 | 18 | ||||
t | 19 | def end(input): | t | 19 | def end(word): |
20 | if len(input) % 3 == 0: | 20 | if len(word) % 3 == 0: | ||
21 | return input[(len(input) // 3) * 2:] | 21 | return word[(len(word) // 3) * 2:] | ||
22 | elif len(input) % 3 == 2 or len(input) % 3 == 1: | 22 | elif len(word) % 3 == 2 or len(word) % 3 == 1: | ||
23 | return input[((len(input) // 3) * 2) + 1:] | 23 | return word[((len(word) // 3) * 2) + 1:] | ||
24 | 24 | ||||
25 | 25 | ||||
26 | def split_sentence(sentence): | 26 | def split_sentence(sentence): | ||
27 | output = [] | 27 | output = [] | ||
28 | for word in sentence.split(): | 28 | for word in sentence.split(): | ||
29 | output.append((beginning(word), middle(word), end(word))) | 29 | output.append((beginning(word), middle(word), end(word))) | ||
30 | return output | 30 | return output |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | 2 | ||||
n | 3 | def beginning(str): | n | 3 | def beginning(input): |
4 | if(len(str) % 3 == 0 or len(str) % 3 == 1): | 4 | if len(input) % 3 == 0 or len(input) % 3 == 1: | ||
5 | return str[0:len(str) // 3] | 5 | return input[:len(input) // 3] | ||
6 | elif(len(str) % 3 == 2): | 6 | elif len(input) % 3 == 2: | ||
7 | return str[0:len(str) // 3 + 1] | 7 | return input[:len(input) // 3 + 1] | ||
8 | #elif(len(str) % 3 == 1): | ||||
9 | #return str[0:len(str) // 3] | ||||
10 | 8 | ||||
11 | 9 | ||||
n | 12 | def middle(str): | n | 10 | def middle(input): |
13 | if(len(str) % 3 == 0): | 11 | if len(input) % 3 == 0: | ||
14 | return str[len(str) // 3:(len(str) // 3) * 2] | 12 | return input[len(input) // 3:(len(input) // 3) * 2] | ||
15 | elif(len(str) % 3 == 2): | 13 | elif len(input) % 3 == 2: | ||
16 | return str[(len(str) // 3) + 1:(len(str) // 3) * 2 + 1] | 14 | return input[(len(input) // 3) + 1:(len(input) // 3) * 2 + 1] | ||
17 | elif(len(str) % 3 == 1): | 15 | elif len(input) % 3 == 1: | ||
18 | return str[len(str) // 3:((len(str) // 3) * 2) + 1] | 16 | return input[len(input) // 3:((len(input) // 3) * 2) + 1] | ||
19 | 17 | ||||
20 | 18 | ||||
n | 21 | def end(str): | n | 19 | def end(input): |
22 | if(len(str) % 3 == 0): | 20 | if len(input) % 3 == 0: | ||
23 | return str[(len(str) // 3) * 2:] | 21 | return input[(len(input) // 3) * 2:] | ||
24 | elif(len(str) % 3 == 2 or len(str) % 3 == 1): | 22 | elif len(input) % 3 == 2 or len(input) % 3 == 1: | ||
25 | return str[((len(str) // 3) * 2) + 1:] | 23 | return input[((len(input) // 3) * 2) + 1:] | ||
26 | #elif(len(str) % 3 == 1): | ||||
27 | #return str[((len(str) // 3) * 2) + 1:] | ||||
28 | 24 | ||||
29 | 25 | ||||
30 | def split_sentence(sentence): | 26 | def split_sentence(sentence): | ||
n | 31 | myList = [] | n | 27 | output = [] |
32 | for word in sentence.split(): | 28 | for word in sentence.split(): | ||
t | 33 | t = (beginning(word), middle(word), end(word)) | t | 29 | output.append((beginning(word), middle(word), end(word))) |
34 | myList.append(t) | 30 | return output | ||
35 | return myList |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | 2 | ||||
n | 3 | def beginnig(str): | n | 3 | def beginning(str): |
4 | if(len(str) % 3 == 0 or len(str) % 3 == 1): | 4 | if(len(str) % 3 == 0 or len(str) % 3 == 1): | ||
5 | return str[0:len(str) // 3] | 5 | return str[0:len(str) // 3] | ||
6 | elif(len(str) % 3 == 2): | 6 | elif(len(str) % 3 == 2): | ||
7 | return str[0:len(str) // 3 + 1] | 7 | return str[0:len(str) // 3 + 1] | ||
8 | #elif(len(str) % 3 == 1): | 8 | #elif(len(str) % 3 == 1): | ||
9 | #return str[0:len(str) // 3] | 9 | #return str[0:len(str) // 3] | ||
10 | 10 | ||||
11 | 11 | ||||
12 | def middle(str): | 12 | def middle(str): | ||
13 | if(len(str) % 3 == 0): | 13 | if(len(str) % 3 == 0): | ||
14 | return str[len(str) // 3:(len(str) // 3) * 2] | 14 | return str[len(str) // 3:(len(str) // 3) * 2] | ||
15 | elif(len(str) % 3 == 2): | 15 | elif(len(str) % 3 == 2): | ||
16 | return str[(len(str) // 3) + 1:(len(str) // 3) * 2 + 1] | 16 | return str[(len(str) // 3) + 1:(len(str) // 3) * 2 + 1] | ||
17 | elif(len(str) % 3 == 1): | 17 | elif(len(str) % 3 == 1): | ||
18 | return str[len(str) // 3:((len(str) // 3) * 2) + 1] | 18 | return str[len(str) // 3:((len(str) // 3) * 2) + 1] | ||
19 | 19 | ||||
20 | 20 | ||||
21 | def end(str): | 21 | def end(str): | ||
22 | if(len(str) % 3 == 0): | 22 | if(len(str) % 3 == 0): | ||
23 | return str[(len(str) // 3) * 2:] | 23 | return str[(len(str) // 3) * 2:] | ||
24 | elif(len(str) % 3 == 2 or len(str) % 3 == 1): | 24 | elif(len(str) % 3 == 2 or len(str) % 3 == 1): | ||
25 | return str[((len(str) // 3) * 2) + 1:] | 25 | return str[((len(str) // 3) * 2) + 1:] | ||
26 | #elif(len(str) % 3 == 1): | 26 | #elif(len(str) % 3 == 1): | ||
27 | #return str[((len(str) // 3) * 2) + 1:] | 27 | #return str[((len(str) // 3) * 2) + 1:] | ||
28 | 28 | ||||
29 | 29 | ||||
30 | def split_sentence(sentence): | 30 | def split_sentence(sentence): | ||
31 | myList = [] | 31 | myList = [] | ||
32 | for word in sentence.split(): | 32 | for word in sentence.split(): | ||
t | 33 | t = (beginnig(word), middle(word), end(word)) | t | 33 | t = (beginning(word), middle(word), end(word)) |
34 | myList.append(t) | 34 | myList.append(t) | ||
35 | return myList | 35 | return myList |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|