def eye(n, K):
    """
    Returns an identity matrix of size n.

    Examples
    ========

    >>> from sympy.matrices.densetools import eye
    >>> from sympy import ZZ
    >>> eye(3, ZZ)
    [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    """
    result = []
    for i in range(n):
        result.append([])
        for j in range(n):
            if i == j:
                result[i].append(K(1))
            else:
                result[i].append(K.zero)
    return result