Calculates the Longest Common Subsequence between p and l (both list of int) and returns its length

def _lcs(p, l):
        """ Calculates the Longest Common Subsequence between p and l (both list of int) and returns its length"""
        # Dynamic Programming Finding LCS
        if len(p) == 0:
            return 0
        P = np.array(list(p)).reshape((1, len(p)))
        L = np.array(list(l)).reshape((len(l), 1))
        M = np.ndarray(shape=(len(P), len(L)), dtype=np.int32)
        for i in range(M.shape[0]):
            for j in range(M.shape[1]):
                up = 0 if i == 0 else M[i-1, j]
                left = 0 if j == 0 else M[i, j-1]

                if i == 0 or j == 0:
                    M[i, j] = max(up, left, M[i, j])
                else:
                    M[i, j] = M[i, j] + M[i - 1, j - 1]
        return M.max()