concept loop in category dask

appears as: loops, loop
Data Science with Python and Dask

This is an excerpt from Manning's book Data Science with Python and Dask.

From a programming perspective, this might sound like directed acyclic graphs would not allow looping operations. But this is not necessarily the case: a directed acyclic graph can be constructed from deterministic loops (such as for loops) by copying the nodes to be repeated and connecting them sequentially. In figure 1.3, the guanciale was sautéed in two different steps—first alone, then together with the onions. If the ingredients needed to be sautéed a non-deterministic number of times, the process could not be expressed as an acyclic graph.

Listing 9.6 Finding all instances of the delimiter
with open('foods.txt', 'rb') as file_handle:
    size = file_handle.seek(0,2) – 1    #1  
    more_data = True    #2  
    output = []
    current_position = next_position = 0
    while more_data:
        if current_position >= size:    #3  
            more_data = False
        else:
            current_position, next_position = get_next_part(file_handle, current_position, 0)
            output.append((current_position, next_position))
            current_position = current_position + next_position + 2

#1   Get the total size of the file in bytes.
#2   Initialize a few variables to control the loop and store the output, starting at byte 0.
#3   If the end of the file has been reached, terminate the loop; otherwise, find the next instance of the delimiter starting at the current position; append the results to the output list, and update the current position to after the delimiter.