code: def l_objective(model,objective=None):
      
  
      if objective is None:
          objective = LExpression()
  
      #initialise with a dummy
      model.objective = Objective(expr = 0.)
      model.objective._expr = _build_sum_expression(objective.variables, constant=objective.constant)
docs: A replacement for pyomo's Objective that quickly builds linear
      objectives.
  
      Instead of
  
      model.objective = Objective(expr=sum(vars[i]*coeffs[i] for i in index)+constant)
  
      call instead
  
      l_objective(model,objective)
  
      where objective is an LExpression.
  
      Variables may be repeated with different coefficients, which pyomo
      will sum up.
  
  
      Parameters
      ----------
      model : pyomo.environ.ConcreteModel
      objective : LExpression