def is_valid(locs):
    return all(y - x >= 2 for x, y in zip(locs, locs[1:]))

def fill_from(size, locs):
    locs = set(locs)
return [int(i in locs) for i in range(size)]
How to check for adjacency in list, then fix adjacency in python