Test Setup Failed
Push — master ( aae629...bbec43 )
by Ken M.
02:50
created

long_repeat()   B

Complexity

Conditions 6

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 10
rs 8
c 0
b 0
f 0
1
from collections import Counter
2
3
4
def long_repeat(line):
5
    # length the longest substring that consists of the same char
6
    if len(line) >= 2:
7
        slice_index = [index for index, value in enumerate(line[:-1])
8
                       if value != line[index + 1]]
9
        values = [slice_index[index + 1] - value
10
                  for index, value in enumerate(slice_index[:-1])]
11
        if values:
12
            return max(values)
13
    return len(line)
14
15
16
if __name__ == '__main__':
17
    # These "asserts" using only for self-checking
18
    # and not necessary for auto-testing
19
    assert long_repeat('sdsffffse') == 4, "First"
20
    assert long_repeat('ddvvrwwwrggg') == 3, "Second"
21
    assert long_repeat('abababaab') == 2, "Third"
22
    assert long_repeat('') == 0, "Empty"
23
    print('"Run" is good. How is "Check"?')
24