Домашни > Man who speaks the ends of words > Решения > Решението на Михаил Цанков

Резултати
10 точки от тестове
0 точки от учител

10 точки общо

12 успешни теста
0 неуспешни теста
Код

 1def get_split_index(word):
 2    w_len = len(word)
 3
 4    if w_len%3 == 2:
 5        return (w_len + 1) // 3
 6
 7    return w_len // 3
 8
 9def beginning(word):
10    return word[:get_split_index(word)]
11
12def middle(word):
13    split_index = get_split_index(word)
14    return word if len(word) == 1 else word[split_index:-split_index]
15
16def end(word):
17    return '' if len(word) == 1 else word[-get_split_index(word):]
18
19def split_word(word):
20    return beginning(word), middle(word), end(word)
21
22def split_sentence(sentence):
23    return [split_word(word) for word in sentence.split()]

............
----------------------------------------------------------------------
Ran 12 tests in 0.000s

OK

Дискусия
История

f1def get_split_index(word):f1def get_split_index(word):
2    w_len = len(word)2    w_len = len(word)
33
n4    if(w_len%3 == 2):n4    if w_len%3 == 2:
5        return (w_len+1)//35        return (w_len + 1) // 3
66
t7    return w_len//3t7    return w_len // 3
88
9def beginning(word):9def beginning(word):
10    return word[:get_split_index(word)]10    return word[:get_split_index(word)]
1111
12def middle(word):12def middle(word):
13    split_index = get_split_index(word)13    split_index = get_split_index(word)
14    return word if len(word) == 1 else word[split_index:-split_index]14    return word if len(word) == 1 else word[split_index:-split_index]
1515
16def end(word):16def end(word):
17    return '' if len(word) == 1 else word[-get_split_index(word):]17    return '' if len(word) == 1 else word[-get_split_index(word):]
1818
19def split_word(word):19def split_word(word):
20    return beginning(word), middle(word), end(word)20    return beginning(word), middle(word), end(word)
2121
22def split_sentence(sentence):22def split_sentence(sentence):
23    return [split_word(word) for word in sentence.split()]23    return [split_word(word) for word in sentence.split()]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def get_split_index(word):f1def get_split_index(word):
2    w_len = len(word)2    w_len = len(word)
n3    return int((w_len+0.5*(w_len%3))//3) # it's not practical, but it is cool :)n3 
4    if(w_len%3 == 2):
5        return (w_len+1)//3
6 
7    return w_len//3
48
5def beginning(word):9def beginning(word):
6    return word[:get_split_index(word)]10    return word[:get_split_index(word)]
711
8def middle(word):12def middle(word):
9    split_index = get_split_index(word)13    split_index = get_split_index(word)
n10    return word if len(word)==1 else word[split_index:-split_index]n14    return word if len(word) == 1 else word[split_index:-split_index]
1115
12def end(word):16def end(word):
n13    return '' if len(word)==1 else word[-get_split_index(word):]n17    return '' if len(word) == 1 else word[-get_split_index(word):]
1418
15def split_word(word):19def split_word(word):
16    return beginning(word), middle(word), end(word)20    return beginning(word), middle(word), end(word)
1721
18def split_sentence(sentence):22def split_sentence(sentence):
t19    return [split_word(word) for word in sentence.split(' ')]t23    return [split_word(word) for word in sentence.split()]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op