def EncodeFromLinkArray(m,N,L):
    """
    EncodeFromLinkArray(m,N,L):

    m:    A list of 0s and 1s representing 'message bits'.
    N:    Length of the code.
    L:    A link array representing rows in a binary generator matrix.
          Specifically, L[i] contains a list indicating the positions
          in row i of the generator matrix which are a 1.

          For example, consider the generator matrix

          G = [1 1 1 0 1 0 0]
              [0 1 1 1 0 1 0]
              [0 0 1 1 1 0 1]

          To encode the message vector [1,0,1], you would do

>>> EncodeFromLinkArray([1,0,1],7,[[0,1,2,4],[1,2,3,5],[2,3,4,6]])
[1, 1, 0, 1, 0, 0, 1]

    """
    result = [0]*N
    for i in range(len(m)):
        assert(m[i] == 0 or m[i] == 1)
        if (m[i]):
            for index in L[i]:
                result[index] = result[index] ^ m[i] 
        
    return result