def pack_shards(used_images, num_shards):
 sorted_images = sorted(used_images, key=(lambda x: x[1]), reverse=True)
 shards = []
 for i in range(0, num_shards):
  shards.append({'images': [], 'sum': 0})
 for image in sorted_images:
  shard = min(shards, key=(lambda x: x['sum']))
  shard['images'].append(image)
  shard['sum'] += image[1]
 return shards

def pack_shards ( used_images , num_shards ) : sorted_images = sorted ( used_images , key = ( lambda x : x [ 1 ] ) , reverse = True ) shards = [ ] for i in range ( 0 , num_shards ) : shards . append ( { 'images' : [ ] , 'sum' : 0 } ) for image in sorted_images : shard = min ( shards , key = ( lambda x : x [ 'sum' ] ) ) shard [ 'images' ] . append ( image ) shard [ 'sum' ] += image [ 1 ] return shards
determines an approximation of the optimal way to pack the images into a given number of shards so as to equalize the execution time amongst the shards .