What about creating a small function that turns the lists into strings and runs a regex against it, You could tidy this up, or I could if you approve this concept
I’m not a regex, expert I’m sure there is another way to do this without using the AttribeError
but this will work, someone can improve this, but it works.
import re
def finder(s):
s="".join(str(s))
match = re.search(r'0\,\s10,(\s10,)*\s0', s)
try:
if (match.group(0)):
return True
except AttributeError:
pass
match = re.search(r'10\,\s0,(\s0,)*\s10', s)
try:
if (match.group(0)):
return True
except AttributeError:
return False
l1 = [7, 7, 7, 7, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 7, 7, 7]
l2 = [10, 10, 10, 10, 0, 0, 0, 10, 10, 10, 10]
l3 = [5, 5, 3, 1, 0, 1, 1, 1, 8, 10, 0, 8, 9, 9, 5]
print(finder(l1))
print(finder(l2))
print(finder(l3))
(xenial)vash@localhost:~/python/stack_overflow/sept$ python3.7 check.py True True False
6
solved verify continuous segments in list [closed]