chain.from_iterable( repeat(load) ) in Python -


i have following snippet in python.

for idx, row in enumerate(    islice (        chain.from_iterable(              repeat(load)),        task_id, min(task_id + step_size, last_step) )): 

here, load list created reading input csv file. after searching on line, understand purposes of function calls islice , chain_from_iterable. question me here is: why need repeat(load) here? mean make copies of list obtained input csv file , handle them based on task_id or things that? sort of in parallel fashion? pretty sure can learn python well, right kindof new python.

the repeat() iterator makes load rows endless; can iterate on forever.

presumably actual code looks this:

for idx, row in enumerate(    islice(        chain.from_iterable(repeat(load)),        task_id, min(task_id + step_size, last_step)    )): 

e.g. repeat(load) chained, data in csv file looks 1 long sequence of rows, , when reach end of csv file start @ beginning again, if rows in csv file read endless loop.

the islice() picks subset of endless loop. making load rows endless, doesn't matter if slice tries take more rows file present.


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -