def func(L, N):

    def key(i_e):
        i, e = i_e
return e == N or i > 0 and L[i - 1] == N or i < len(L) and L[i + 1] == N
return [[e for i, e in g if e != N] for k, g in itertools.groupby(enumerate
    (L), key) if k]
Поиск соседей в списке