1def divide(word, divider=3):
2 return len(word) // divider, len(word) % divider
3
4def beginning(word):
5 whole, remainder = divide(word)
6 return word[:whole + remainder // 2]
7
8def middle(word):
9 whole, remainder = divide(word)
10 return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)]
11
12def end(word):
13 whole, remainder = divide(word)
14 return word[2 * whole + (1 if remainder > 0 else 0):]
15
16def split_sentence(sentence):
17 return [(beginning(word), middle(word), end(word)) for word in sentence.split()]
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
n | 1 | def divide(word, divider = 3): | n | 1 | def divide(word, divider=3): |
2 | return len(word) // divider, len(word) % divider | 2 | return len(word) // divider, len(word) % divider | ||
n | 3 | n | 3 | ||
4 | def beginning(word): | 4 | def beginning(word): | ||
5 | whole, remainder = divide(word) | 5 | whole, remainder = divide(word) | ||
6 | return word[:whole + remainder // 2] | 6 | return word[:whole + remainder // 2] | ||
7 | 7 | ||||
8 | def middle(word): | 8 | def middle(word): | ||
9 | whole, remainder = divide(word) | 9 | whole, remainder = divide(word) | ||
10 | return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)] | 10 | return word[whole + remainder // 2:2 * whole + (1 if remainder > 0 else 0)] | ||
11 | 11 | ||||
12 | def end(word): | 12 | def end(word): | ||
13 | whole, remainder = divide(word) | 13 | whole, remainder = divide(word) | ||
14 | return word[2 * whole + (1 if remainder > 0 else 0):] | 14 | return word[2 * whole + (1 if remainder > 0 else 0):] | ||
15 | 15 | ||||
16 | def split_sentence(sentence): | 16 | def split_sentence(sentence): | ||
t | 17 | return [(beginning(word), middle(word), end(word)) for word in sentence.split(' ')] | t | 17 | return [(beginning(word), middle(word), end(word)) for word in sentence.split()] |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|