def _serialize_inventories(inventories, generation):
 inventories_by_class = {inventory.resource_class: inventory for inventory in inventories}
 inventories_dict = {}
 for (resource_class, inventory) in inventories_by_class.items():
  inventories_dict[resource_class] = _serialize_inventory(inventory, generation=None)
 return {'resource_provider_generation': generation, 'inventories': inventories_dict}

def _serialize_inventories ( inventories , generation ) : inventories_by_class = { inventory . resource_class : inventory for inventory in inventories } inventories_dict = { } for ( resource_class , inventory ) in inventories_by_class . items ( ) : inventories_dict [ resource_class ] = _serialize_inventory ( inventory , generation = None ) return { 'resource_provider_generation' : generation , 'inventories' : inventories_dict }
turn a list of inventories in a dict by resource class .