import itertools


def list_of_first_n(v,n):
    """
    Given an iterator v, return first n elements it produces as a list.

    INPUT:

    - ``v`` - an iterator

    - ``n`` - an integer

    OUTPUT:

    - a list

    EXAMPLES::

        sage: sage.server.notebook.interact.list_of_first_n(Primes(), 10)
        [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
        sage: sage.server.notebook.interact.list_of_first_n((1..5), 10)
        [1, 2, 3, 4, 5]
        sage: sage.server.notebook.interact.list_of_first_n(QQ, 10)
        [0, 1, -1, 1/2, -1/2, 2, -2, 1/3, -1/3, 3]
    """
    return list(itertools.islice(v, 0, n))