Q:

Define new words collection of predefined size by parsing a given words collection from beginning

I have a collection of words(700 in number). I need to parse the words from beginning of this collection to fill my new collection up to a point that the total number of words of my new collection reaches 1024(predefined number).
Example:
collection 1: aaa bbb ccc ddd eee fff ggg hhh iii jjj
collection 1 size: 10 words

collection 2: aaa bbb ccc ddd eee fff ggg hhh iii jjj aaa bbb ccc ddd eee
collection 2 size: 15 words(desired/predefined size)

A:

You can use itertools cycle and islice for this. cycle will give you a repeating iterator of the list and islice will let you pluck of the number you want. For example to get repeating set of 20 from the list of 10:
from itertools import cycle, islice

collection = "aaa bbb ccc ddd eee fff ggg hhh iii jjj".split()
sample = islice(cycle(collection), 20)
print(list(sample))

result:
['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj', 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj']

