Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My Improved second solution solution in Clear category for Long Repeat by mikaeldovbnia
def long_repeat(line):
# In this if statement I check if line is False.
if line == '':
return 0
f = ''
# I make the for statement with the function enumerate to be able to work with indexes.
for index_, element_ in enumerate(line):
# I check if my index equals the last index in line. I break to prevent the IndexError.
if index_ == (len(line) - 1):
f += element_
break
# In this if statement I check if the next element in line doesn't equal my current element in line.
# And separate them to something like this 's d s ffff s e ' and the second example: 'dd vv r www r ggg ' if the
# answer is True
if line[index_ + 1] != element_:
f += (element_ + ' ')
# and last of all I just add element. This else is the same thing like this elif: elif line[index_ + 1]
# == element_
else:
f += element_
# the end of the define function is easy. I make g that eqals f.split(). g is now ['s', 'd', 's', 'ffff', 's', 'e'].
#Then I make a list out of the lengths of the elements that I instantly check for the max element and return it.
g = f.split()
return max(len(i) for i in g)
# this is the end of my solution
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"?')
Nov. 15, 2022
Comments: