futures processing results as completed what if we want to process each of the results returned by our collection of futureswe could loop through the futures list in the previous section once all the results have been generated howeverthis means that we would have to wait for them all to complete before processing the list in many situations we would like to process the results as soon as they are generated without being concerned if that is the firstthirdlast or second etc the concurrent futures as_completed(function does preciously thisit will serve up each future in turn as soon as they are completedwith all futures eventually being returned but without guaranteeing the order (just that as soon as future is finished generating result it will be immediately availablefor examplein the following examplethe is_even(function sleeps for random number of seconds (ensuring that different invocations of this function will take different durationsthen calculates resultfrom concurrent futures import threadpoolexecutoras_completed from time import sleep from random import randint def is_even( )print('checking if' 'is even'sleep(randint( )return str(nstr( = print('started'data [ pool threadpoolexecutor( futures [for in datafutures append(pool submit(is_evenv)for in as_completed(futures)print( result()print('done'the second for loop will loop through each future as they complete printing out the result from eachas shown below