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