So I need to know if in a string which contains only '1's and '0's has 7 of one of those in a row. My first thought was to iterate through the string like so:
for i in inp:
if count == 6:
answ = True
this = i
if this == other:
count+=1
other = this
else:
other = this
count = 0
But it randomly gives out a wrong answer. My next idea was to use regex (.)\1{7,}
like this:
pattern = re.compile(r'(.)\1{7,}')
found = re.search(pattern, inp)
if found != None:
answ = True
But it still sometimes makes mistakes. Anyone has any ideas on why that would happen? Regex was taken from here