Long Repeat
from itertools import groupby
def long_repeat(line):
"""
字典分组函数 itertools.groupby()能看的懂的写法
"""
# if line :
# m = [[k, len(list(g))] for k, g in groupby(line)]
# print(m)
# return max(dict(m).values())
# else:
# return 0
"""
高级看了不知道怎么回事的写法
"""
return max(len(list(g)) for _, g in groupby(line)) if line else 0
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert long_repeat('sdsffffse') == 4, "First"
assert long_repeat('ddvvrwwwrggg') == 3, "Second"
assert long_repeat('abababaab') == 2, "Third"
assert long_repeat('') == 0, "Empty"
print('"Run" is good. How is "Check"?')