How to set element-wise Dirichlet boundary condition?

Hello, I am new to Fenics. Suppose:

from dolfin import *
mesh = UnitSquareMesh(4, 4)
V = FunctionSpace(mesh, "Lagrange", 1)
def boundary(x):
    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

There should be 8 ‘line’ elements on both side and I want to supply an array of 8 numbers to set the boundary condition. How shall I achieve this? I only know that supplying an expression would work but haven’t googled anything about supplying an arbitrary vector/matrix.

Thanks in advance!