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