import itertools


def take(n, gen):
    """Take the first n items from the generator gen. Return a list of that many items
    and the resulting state of the generator."""
    lst = list(itertools.islice(gen, n))
    return lst, gen