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
Post a Comment