I have made a generator to read a file word by word and it works nicely.
def word_reader(file): for line in open(file): for p in line.split():
Use cytoolz.take.
>>> from cytoolz import take >>> list(take(2, [10, 20, 30, 40, 50])) [10, 20]